Skip to content

Commit 4fad0e1

Browse files
authored
refactor!: Migrate project management workflows to actions (#167)
* Migrate project management workflows to actions * Add missing secret * Fix add team label workflow * Add test to all-jobs-completed
1 parent 1d544ef commit 4fad0e1

File tree

9 files changed

+193
-213
lines changed

9 files changed

+193
-213
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Add Issue/PR to Project By Team'
2+
description: 'Adds an issue or pull request to a GitHub Project if it matches the specified team criteria.'
3+
4+
inputs:
5+
project-url:
6+
description: 'URL of the GitHub Project where items should be added.'
7+
required: true
8+
team-name:
9+
description: 'Team name to match for PR review_requested or requested_team.'
10+
required: true
11+
team-label:
12+
description: 'Label that indicates the Issue/PR belongs to the team.'
13+
required: true
14+
filter-enabled:
15+
description: 'If true, only add items that match the team criteria. If false, add every item.'
16+
required: false
17+
default: 'true'
18+
github-token:
19+
description: 'GitHub token with access to the project.'
20+
required: true
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- name: Add item to project board
26+
uses: actions/[email protected]
27+
# If filtering is disabled, the condition is always true.
28+
# If filtering is enabled, then:
29+
# - For PRs, check that the PR either has the specified team in requested_team
30+
# or contains the team label.
31+
# - For Issues, check that the issue contains the team label.
32+
if: |
33+
inputs.filter-enabled != 'true' ||
34+
((github.event_name == 'pull_request' &&
35+
(
36+
github.event.requested_team.name == inputs.team-name ||
37+
contains(github.event.pull_request.labels.*.name, inputs.team-label) ||
38+
contains(github.event.pull_request.requested_teams.*.name, inputs.team-name)
39+
)
40+
)
41+
||
42+
(github.event_name == 'issues' &&
43+
(
44+
contains(github.event.issue.labels.*.name, inputs.team-label)
45+
)
46+
))
47+
with:
48+
project-url: ${{ inputs.project-url }}
49+
github-token: ${{ inputs.github-token }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Add Team Label
2+
description: "Adds a GitHub team label to a pull request based on the author's entry in the MetaMask topology file."
3+
4+
inputs:
5+
team-label-token:
6+
description: 'GitHub token with access to read topology.json and add labels to PRs.'
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
# Fetch the team label for the PR author from topology.json and expose it as a step output.
13+
- name: Get team label
14+
id: get-team-label
15+
env:
16+
GH_TOKEN: ${{ inputs.team-label-token }}
17+
USER: ${{ github.event.pull_request.user.login }}
18+
shell: bash
19+
run: |
20+
# Stream topology.json through jq, find the first team where USER appears in members, pm, em, or tl, and emit
21+
# its githubLabel.name value.
22+
team_label=$(gh api -H 'Accept: application/vnd.github.raw' 'repos/metamask/metamask-planning/contents/topology.json' | jq -r --arg USER "$USER" '.[] | select(any(.members[]?; . == $USER) or (.pm // empty) == $USER or (.em // empty) == $USER or (.tl // empty) == $USER) | .githubLabel.name' | head -n 1)
23+
if [ -z "$team_label" ]; then
24+
echo "::error::Team label not found for author: $USER. Please open a pull request with your GitHub handle and team label to update topology.json at https://github.com/MetaMask/MetaMask-planning/blob/main/topology.json"
25+
exit 1
26+
fi
27+
echo "TEAM_LABEL=$team_label" >> "$GITHUB_OUTPUT"
28+
29+
# Apply the retrieved label to the pull request using the GitHub CLI.
30+
- name: Add team label
31+
env:
32+
GH_TOKEN: ${{ inputs.team-label-token }}
33+
PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
34+
TEAM_LABEL: ${{ steps.get-team-label.outputs.TEAM_LABEL }}
35+
shell: bash
36+
run: |
37+
gh issue edit "$PULL_REQUEST_URL" --add-label "$TEAM_LABEL"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: 'Close stale issues and PRs'
2+
description: 'Automatically mark issues and pull requests as stale after a period of inactivity, and close them after an additional period of inactivity.'
3+
4+
inputs:
5+
stale-issue-message:
6+
description: 'Message to post when marking an issue as stale'
7+
required: false
8+
default: 'This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in 60 days. Thank you for your contributions.'
9+
close-issue-message:
10+
description: 'Message to post when closing a stale issue'
11+
required: false
12+
default: 'This issue was closed because there has been no follow activity in 90 days. If you feel this was closed in error please provide evidence on the current production app in a new issue or comment in the existing issue to a maintainer. Thank you for your contributions.'
13+
stale-issue-label:
14+
description: 'Label to use when marking an issue as stale'
15+
required: false
16+
default: 'stale'
17+
any-of-issue-labels:
18+
description: 'Comma-separated list of labels to check for issues'
19+
required: false
20+
default: 'needs-information, needs-reproduction'
21+
exempt-issue-labels:
22+
description: 'Comma-separated list of labels that exempt issues from being marked as stale'
23+
required: false
24+
default: 'type-security, feature-request, Sev1-high, needs-triage'
25+
days-before-issue-stale:
26+
description: 'Number of days of inactivity before an issue becomes stale'
27+
required: false
28+
default: 30
29+
days-before-issue-close:
30+
description: 'Number of days of inactivity before a stale issue is closed'
31+
required: false
32+
default: 60
33+
stale-pr-message:
34+
description: 'Message to post when marking a PR as stale'
35+
required: false
36+
default: 'This PR has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 7 days. Thank you for your contributions.'
37+
stale-pr-label:
38+
description: 'Label to use when marking a PR as stale'
39+
required: false
40+
default: 'stale'
41+
exempt-pr-labels:
42+
description: 'Comma-separated list of labels that exempt PRs from being marked as stale'
43+
required: false
44+
default: 'work-in-progress, external-contributor'
45+
close-pr-message:
46+
description: 'Message to post when closing a stale PR'
47+
required: false
48+
default: 'This PR was closed because there has been no follow up activity in 7 days. Thank you for your contributions.'
49+
days-before-pr-stale:
50+
description: 'Number of days of inactivity before a PR becomes stale'
51+
required: false
52+
default: '90'
53+
days-before-pr-close:
54+
description: 'Number of days of inactivity before a stale PR is closed'
55+
required: false
56+
default: '7'
57+
operations-per-run:
58+
description: 'Maximum number of operations to perform per run'
59+
required: false
60+
default: '200'
61+
62+
runs:
63+
using: composite
64+
steps:
65+
- uses: actions/stale@v10
66+
with:
67+
stale-issue-message: ${{ inputs.stale-issue-message }}
68+
close-issue-message: ${{ inputs.close-issue-message }}
69+
stale-issue-label: ${{ inputs.stale-issue-label }}
70+
any-of-issue-labels: ${{ inputs.any-of-issue-labels }}
71+
exempt-issue-labels: ${{ inputs.exempt-issue-labels }}
72+
days-before-issue-stale: ${{ inputs.days-before-issue-stale }}
73+
days-before-issue-close: ${{ inputs.days-before-issue-close }}
74+
stale-pr-message: ${{ inputs.stale-pr-message }}
75+
stale-pr-label: ${{ inputs.stale-pr-label }}
76+
exempt-pr-labels: ${{ inputs.exempt-pr-labels }}
77+
close-pr-message: ${{ inputs.close-pr-message }}
78+
days-before-pr-stale: ${{ inputs.days-before-pr-stale }}
79+
days-before-pr-close: ${{ inputs.days-before-pr-close }}
80+
operations-per-run: ${{ inputs.operations-per-run }}

.github/workflows/add-item-to-project.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

.github/workflows/add-team-label-test.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/add-team-label.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ jobs:
1919
name: Test checkout-and-setup
2020
uses: ./.github/workflows/test-checkout-and-setup.yml
2121

22+
test-add-team-label:
23+
name: Test add-team-label
24+
uses: ./.github/workflows/test-add-team-label.yml
25+
secrets:
26+
TEAM_LABEL_TOKEN: ${{ secrets.TEAM_LABEL_TOKEN }}
27+
2228
all-jobs-completed:
2329
name: All jobs completed
2430
runs-on: ubuntu-latest
2531
needs:
2632
- lint-workflows
2733
- build-lint-test
2834
- test-checkout-and-setup
35+
- test-add-team-label
2936
outputs:
3037
PASSED: ${{ steps.set-output.outputs.PASSED }}
3138
steps:

0 commit comments

Comments
 (0)