Skip to content

Commit 49d1aeb

Browse files
authored
Add github action for automating QA labels
1 parent c6384ed commit 49d1aeb

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

.github/workflows/qa-labels.yml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Add QA labels to Elastic Agent issues
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
7+
jobs:
8+
fetch_issues_to_label:
9+
runs-on: ubuntu-latest
10+
# Only run on PRs that were merged for the Elastic Agent teams
11+
if: |
12+
github.event.pull_request.merged_at &&
13+
(
14+
contains(github.event.pull_request.labels.*.name, 'Team:Elastic-Agent') ||
15+
contains(github.event.pull_request.labels.*.name, 'Team:Elastic-Agent-Data-Plane') ||
16+
contains(github.event.pull_request.labels.*.name, 'Team:Elastic-Agent-Control-Plane')
17+
)
18+
outputs:
19+
matrix: ${{ steps.issues_to_label.outputs.value }}
20+
label_ids: ${{ steps.label_ids.outputs.value }}
21+
steps:
22+
- uses: octokit/graphql-action@v2.x
23+
id: closing_issues
24+
with:
25+
query: |
26+
query closingIssueNumbersQuery($prnumber: Int!) {
27+
repository(owner: "elastic", name: "beats") {
28+
pullRequest(number: $prnumber) {
29+
closingIssuesReferences(first: 10) {
30+
nodes {
31+
id
32+
labels(first: 20) {
33+
nodes {
34+
id
35+
name
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
prnumber: ${{ github.event.number }}
44+
token: ${{ secrets.GITHUB_TOKEN }}
45+
- uses: sergeysova/jq-action@v2
46+
id: issues_to_label
47+
with:
48+
# Map to the issues' node id
49+
cmd: echo $CLOSING_ISSUES | jq -c '.repository.pullRequest.closingIssuesReferences.nodes | map(.id)'
50+
multiline: true
51+
env:
52+
CLOSING_ISSUES: ${{ steps.closing_issues.outputs.data }}
53+
- uses: sergeysova/jq-action@v2
54+
id: label_ids
55+
with:
56+
# Get list of version labels on pull request and map to label's node id, append 'QA:Ready For Testing' id ("LA_kwDOEpQvns7jl5M2")
57+
cmd: echo $PR_LABELS | jq -c 'map(select(.name | test("v[0-9]+\\.[0-9]+\\.[0-9]+")) | .node_id) + ["LA_kwDOEpQvns7jl5M2"]'
58+
multiline: true
59+
env:
60+
PR_LABELS: ${{ toJSON(github.event.pull_request.labels) }}
61+
62+
label_issues:
63+
needs: fetch_issues_to_label
64+
runs-on: ubuntu-latest
65+
# For each issue closed by the PR run this job
66+
strategy:
67+
matrix:
68+
issueNodeId: ${{ fromJSON(needs.fetch_issues_to_label.outputs.matrix) }}
69+
name: Label issue ${{ matrix.issueNodeId }}
70+
steps:
71+
- uses: octokit/graphql-action@v2.x
72+
id: add_labels_to_closed_issue
73+
with:
74+
query: |
75+
mutation add_label($issueid:String!, $labelids:[String!]!) {
76+
addLabelsToLabelable(input: {labelableId: $issueid, labelIds: $labelids}) {
77+
clientMutationId
78+
}
79+
}
80+
issueid: ${{ matrix.issueNodeId }}
81+
labelids: ${{ needs.fetch_issues_to_label.outputs.label_ids }}
82+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)