Repository navigation
94 lines (88 loc) · 3.67 KB
/
Copy pathdev_pr.yml
File metadata and controls
94 lines (88 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: dev_pr
concurrency:
group: ${{ github.repository }}-${{ github.event.pull_request.number }}-${{ github.workflow }}
cancel-in-progress: true
# Trigger whenever a PR is changed (title as well as new / changed commits)
on:
pull_request_target:
types:
- opened
- edited
- synchronize
jobs:
process:
name: Process
runs-on: ubuntu-slim
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Assign GitHub labels
if: |
github.event_name == 'pull_request_target' &&
(github.event.action == 'opened' ||
github.event.action == 'synchronize')
uses: actions/labeler@bf12e9b00b37c5c0ca2b87b79b2daf7891dbda13 # v7.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/workflows/dev_pr/labeler.yml
sync-labels: true
# Copy labels from linked issue if present, to help with changelog generation.
# For simplicity we just run once on open and for first linked issue; its trivial
# for maintainers to fix up the label manually for more complex cases.
copy-issue-labels:
name: Copy labels from (first) closing issue
if: github.event.action == 'opened'
needs: process
runs-on: ubuntu-slim
permissions:
issues: read
pull-requests: write
steps:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { node } = await github.graphql(`
query($id: ID!) {
node(id: $id) {
... on PullRequest {
closingIssuesReferences(first: 1) {
nodes { number repository { nameWithOwner } }
}
}
}
}
`, { id: context.payload.pull_request.node_id });
const issue = node?.closingIssuesReferences?.nodes[0];
const repository = `${context.repo.owner}/${context.repo.repo}`.toLowerCase();
// just in case its referencing an external repo
if (!issue || issue.repository.nameWithOwner.toLowerCase() !== repository) return;
const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
...context.repo, issue_number: issue.number, per_page: 100,
});
// these ones impact changelog generation the most
const allowedLabels = ['bug', 'enhancement', 'development-process', 'performance'];
const labelsToCopy = labels.map(label => label.name).filter(name => allowedLabels.includes(name));
if (labelsToCopy.length) {
await github.rest.issues.addLabels({
...context.repo, issue_number: context.issue.number,
labels: labelsToCopy,
});
}