Skip to content

Commit 049c290

Browse files
authored
Refactor labeler and project workflows (#2317)
* Update permissions on labeler workflow * Align with refactoring in NodeJS agent * Update add to project workflow
1 parent 82c6311 commit 049c290

File tree

2 files changed

+101
-45
lines changed

2 files changed

+101
-45
lines changed

.github/workflows/addToProject.yml

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,90 @@
1-
2-
name: Auto Assign to Project(s)
3-
1+
name: Add to APM Agents Project
42
on:
53
issues:
6-
types: [opened, edited, milestoned]
7-
pull_request_target:
8-
types: [opened, edited, milestoned]
9-
env:
10-
MY_GITHUB_TOKEN: ${{ secrets.APM_TECH_USER_TOKEN }}
4+
types: [ opened, milestoned ]
115

126
permissions:
137
contents: read
148

159
jobs:
16-
assign_one_project:
10+
add_to_project:
11+
if: github.event.issue && github.event.issue.milestone
1712
runs-on: ubuntu-latest
18-
name: Assign milestoned to Project
1913
steps:
20-
- name: Assign issues with milestones to project
21-
uses: elastic/assign-one-project-github-action@1.2.2
22-
if: github.event.issue && github.event.issue.milestone
23-
with:
24-
project: 'https://github.com/orgs/elastic/projects/454'
25-
project_id: '5882982'
26-
column_name: 'Planned'
27-
- name: Assign new pull requests to project
28-
uses: elastic/assign-one-project-github-action@1.2.2
29-
if: github.event.action == 'opened' && github.event.pull_request
30-
with:
31-
project: 'https://github.com/orgs/elastic/projects/454'
32-
project_id: '5882982'
33-
column_name: 'In Progress'
14+
15+
- name: Get project data
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.APM_TECH_USER_TOKEN }}
18+
TEAM: .NET
19+
ORGANIZATION: elastic
20+
PROJECT_NUMBER: 595
21+
run: |
22+
gh api graphql -f query='
23+
query($org: String!, $number: Int!) {
24+
organization(login: $org){
25+
projectV2(number: $number) {
26+
id
27+
fields(first:20) {
28+
nodes {
29+
... on ProjectV2Field {
30+
id
31+
name
32+
}
33+
... on ProjectV2SingleSelectField {
34+
id
35+
name
36+
options {
37+
id
38+
name
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
46+
47+
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
48+
echo 'TEAM_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Team") | .id' project_data.json) >> $GITHUB_ENV
49+
echo 'FIELD_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Team") | .options[] | select(.name== "$TEAM") | .id' project_data.json) >> $GITHUB_ENV
50+
51+
- name: Add issue to project
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.APM_TECH_USER_TOKEN }}
54+
ISSUE_ID: ${{ github.event.issue.node_id }}
55+
run: |
56+
item_id="$( gh api graphql -f query='
57+
mutation($project:ID!, $pr:ID!) {
58+
addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) {
59+
item {
60+
id
61+
}
62+
}
63+
}' -f project=$PROJECT_ID -f pr=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')"
64+
65+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
66+
67+
- name: Set fields
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.APM_TECH_USER_TOKEN }}
70+
run: |
71+
gh api graphql -f query='
72+
mutation (
73+
$project: ID!
74+
$item: ID!
75+
$team_field: ID!
76+
$team_value: String!
77+
) {
78+
set_agent: updateProjectV2ItemFieldValue(input: {
79+
projectId: $project
80+
itemId: $item
81+
fieldId: $team_field
82+
value: {
83+
singleSelectOptionId: $team_value
84+
}
85+
}) {
86+
projectV2Item {
87+
id
88+
}
89+
}
90+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f team_field=$TEAM_FIELD_ID -f team_value=${{ env.FIELD_OPTION_ID }} --silent

.github/workflows/labeler.yml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,37 @@ on:
55
pull_request_target:
66
types: [opened]
77

8+
# '*: write' permissions for https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#add-labels-to-an-issue
89
permissions:
910
contents: read
1011
issues: write
12+
pull-requests: write
1113

1214
jobs:
1315
triage:
1416
runs-on: ubuntu-latest
1517
steps:
16-
- name: Add agent-dotnet label
17-
uses: actions-ecosystem/action-add-labels@v1
18-
with:
19-
labels: agent-dotnet
20-
- name: Check team membership for user
21-
uses: elastic/get-user-teams-membership@1.1.0
22-
id: checkUserMember
18+
19+
- id: is_elastic_member
20+
uses: elastic/apm-pipeline-library/.github/actions/is-member-elastic-org@current
2321
with:
2422
username: ${{ github.actor }}
25-
team: 'apm'
26-
usernamesToExclude: |
27-
apmmachine
28-
dependabot
29-
dependabot[bot]
30-
GITHUB_TOKEN: ${{ secrets.APM_TECH_USER_TOKEN }}
31-
- name: Add community and triage lables
32-
if: steps.checkUserMember.outputs.isTeamMember != 'true' && steps.checkUserMember.outputs.isExcluded != 'true'
33-
uses: actions-ecosystem/action-add-labels@v1
23+
token: ${{ secrets.APM_TECH_USER_TOKEN }}
24+
25+
- name: Add community and triage labels
26+
if: contains(steps.is_elastic_member.outputs.result, 'false') && github.actor != 'dependabot[bot]'
27+
uses: actions/github-script@v7
3428
with:
35-
labels: |
36-
community
37-
triage
29+
script: |
30+
github.rest.issues.addLabels({
31+
issue_number: context.issue.number,
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
labels: ["community", "triage"]
35+
})
36+
3837
- name: Add comment for community PR
39-
if: steps.checkUserMember.outputs.isTeamMember != 'true' && steps.checkUserMember.outputs.isExcluded != 'true'
38+
if: contains(steps.is_elastic_member.outputs.result, 'false') && github.actor != 'dependabot[bot]'
4039
uses: wow-actions/auto-comment@v1
4140
with:
4241
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -45,4 +44,4 @@ jobs:
4544
4645
It may take some time before we review a PR, so even if you don’t see activity for some time, it **does not** mean that we have forgotten about it.
4746
48-
Every once in a while we go through a process of prioritization, after which we are focussing on the tasks that were planned for the upcoming [milestone](https://github.com/elastic/apm-agent-dotnet/milestones). The prioritization status is typically reflected through the PR labels. It could be pending triage, a candidate for a future milestone, or have a target milestone set to it.
47+
Every once in a while we go through a process of prioritization, after which we are focussing on the tasks that were planned for the upcoming [milestone](https://github.com/elastic/apm-agent-dotnet/milestones). The prioritization status is typically reflected through the PR labels. It could be pending triage, a candidate for a future milestone, or have a target milestone set to it.

0 commit comments

Comments
 (0)