Skip to content

Commit 5c288d1

Browse files
committed
feat: let the reminder report on another repository
A repository input (default: the calling repository) makes it possible to run the action from a fork against the real repo, and the name is checked so it can't change the search query.
1 parent 130c9d3 commit 5c288d1

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎.github/actions/remind-dependabot-prs/action.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ description: 'Builds a Slack payload listing open Dependabot PRs grouped by owni
33

44
inputs:
55
github-token:
6-
description: 'Token used to read pull request data from the invoking repository.'
6+
description: 'Token used to read pull request data from the repository.'
77
required: true
8+
repository:
9+
description: 'Repository to report on, as owner/name. Empty uses the invoking repository.'
10+
required: false
11+
default: ''
812
planning-token:
913
description: 'Token with read access to MetaMask/MetaMask-planning (for topology.json).'
1014
required: true
@@ -54,7 +58,7 @@ runs:
5458
id: reminder
5559
shell: bash
5660
env:
57-
GITHUB_REPOSITORY: ${{ github.repository }}
61+
GITHUB_REPOSITORY: ${{ inputs.repository || github.repository }}
5862
GH_TOKEN: ${{ inputs.github-token }}
5963
PLANNING_TOKEN: ${{ inputs.planning-token }}
6064
OWNER_TEAMS: ${{ inputs.owner-teams }}

‎.github/scripts/dependabot-pr-reminder/cli.mts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export async function main(environment: NodeJS.ProcessEnv): Promise<void> {
2626
'GITHUB_REPOSITORY, FALLBACK_TEAM, PLANNING_TOKEN and GITHUB_OUTPUT are required',
2727
);
2828
}
29-
if (repository.split('/').filter(Boolean).length !== 2) {
29+
// The name goes into a search query, so only allow plain owner/name values.
30+
if (!/^[\w.-]+\/[\w.-]+$/u.test(repository)) {
3031
throw new Error('GITHUB_REPOSITORY must be in owner/name form');
3132
}
3233
const ref = environment.TOPOLOGY_REF?.trim()

‎.github/scripts/tests/dependabot-pr-reminder/cli.test.mts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ describe('cli entry point', () => {
2626
* Runs the script with no settings, so it stops at once with a message.
2727
*
2828
* @param scriptPath - The path to run it through.
29+
* @param settings - Environment settings to give it.
2930
* @returns What it printed on stderr.
3031
*/
31-
async function runWithoutSettings(scriptPath: string): Promise<string> {
32+
async function runWithoutSettings(
33+
scriptPath: string,
34+
settings: Record<string, string> = {},
35+
): Promise<string> {
3236
try {
3337
await execFileAsync(process.execPath, [scriptPath], {
34-
env: { PATH: process.env.PATH ?? '' },
38+
env: { PATH: process.env.PATH ?? '', ...settings },
3539
});
3640
} catch (error) {
3741
return (error as { stderr?: string }).stderr ?? '';
@@ -58,4 +62,17 @@ describe('cli entry point', () => {
5862
'are required',
5963
);
6064
});
65+
66+
it.each(['MetaMask/core is:issue', 'MetaMask', 'a/b/c', 'a/b c'])(
67+
'rejects the repository %j before searching',
68+
async (repository) => {
69+
const output = await runWithoutSettings(SCRIPT, {
70+
GITHUB_REPOSITORY: repository,
71+
FALLBACK_TEAM: 'core-platform',
72+
PLANNING_TOKEN: 'token',
73+
GITHUB_OUTPUT: join(tmpdir(), 'reminder-cli-output.txt'),
74+
});
75+
expect(output).toContain('owner/name');
76+
},
77+
);
6178
});

‎.github/workflows/remind-dependabot-prs.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ name: Remind Dependabot PRs
2121
on:
2222
workflow_call:
2323
inputs:
24+
repository:
25+
required: false
26+
type: string
27+
default: ''
28+
description: 'Repository to report on, as owner/name. Empty uses the calling repository'
2429
owner-teams:
2530
required: false
2631
type: string
@@ -87,6 +92,7 @@ jobs:
8792
uses: MetaMask/github-tools/.github/actions/remind-dependabot-prs@v1
8893
with:
8994
github-token: ${{ github.token }}
95+
repository: ${{ inputs.repository }}
9096
planning-token: ${{ steps.planning-token.outputs.token }}
9197
owner-teams: ${{ inputs.owner-teams }}
9298
fallback-team: ${{ inputs.fallback-team }}

0 commit comments

Comments
 (0)