Skip to content

Commit e1b4e26

Browse files
peter-evanspatrickleetvolodymyrZotov
authored
v5 (#431)
* feat: support yml or yaml (#427) test: support yml or yaml chore: lint * Fix getting permissions for the contributors who are a part of the team (#424) * Fix getActorPermission to handle team-based permissions * Use 'user.permissions' object to return permission * Add RepoPermission type * Make new build * feat: update runtime to node 24 * fix: eslint-plugin dep * fix: remove unused type * docs: update whats new --------- Co-authored-by: Patrick Lee Scott <[email protected]> Co-authored-by: Volodymyr Zotov <[email protected]>
1 parent 9a73d03 commit e1b4e26

17 files changed

+653
-615
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v5
1818
- uses: actions/setup-node@v6
1919
with:
20-
node-version: 20.x
20+
node-version-file: package.json
2121
cache: npm
2222
- run: npm ci
2323
- run: npm run build
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Hello yaml Command
2+
on:
3+
repository_dispatch:
4+
types: [hello-yaml-local-command]
5+
jobs:
6+
helloYaml:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Add reaction
10+
uses: peter-evans/create-or-update-comment@v4
11+
with:
12+
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
13+
reactions: hooray
14+
15+
- name: Create URL to the run output
16+
id: vars
17+
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
18+
19+
- name: Create comment
20+
uses: peter-evans/create-or-update-comment@v4
21+
with:
22+
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
23+
body: |
24+
Hello @${{ github.event.client_payload.github.actor }}!
25+
26+
This command was in a workflow file with the `.yaml` extension.
27+
28+
[Click here to see the command run output][1]
29+
30+
[1]: ${{ steps.vars.outputs.run-url }}

.github/workflows/slash-command-dispatch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
with:
2020
token: ${{ secrets.REPO_ACCESS_TOKEN }}
2121
commands: |
22+
hello-yaml-local
2223
hello-world-local
2324
ping-local
2425
permission: none

.github/workflows/update-major-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
type: choice
1212
description: The major version tag to update
1313
options:
14-
- v4
14+
- v5
1515

1616
jobs:
1717
tag:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
runs-on: ubuntu-latest
5555
steps:
5656
- name: Slash Command Dispatch
57-
uses: peter-evans/slash-command-dispatch@v4
57+
uses: peter-evans/slash-command-dispatch@v5
5858
with:
5959
token: ${{ secrets.PAT }}
6060
commands: |
@@ -102,7 +102,7 @@ You can use a [PAT](https://docs.github.com/en/github/authenticating-to-github/c
102102

103103
```yml
104104
- name: Slash Command Dispatch
105-
uses: peter-evans/slash-command-dispatch@v4
105+
uses: peter-evans/slash-command-dispatch@v5
106106
with:
107107
token: ${{ secrets.PAT }}
108108
reaction-token: ${{ secrets.PAT }}
@@ -178,7 +178,7 @@ It will also contain any static arguments if configured.
178178

179179
To demonstrate, take the following configuration as an example.
180180
```yml
181-
- uses: peter-evans/slash-command-dispatch@v4
181+
- uses: peter-evans/slash-command-dispatch@v5
182182
with:
183183
token: ${{ secrets.PAT }}
184184
commands: |
@@ -248,7 +248,7 @@ The simplest response is to add a :tada: reaction to the comment.
248248

249249
```yml
250250
- name: Add reaction
251-
uses: peter-evans/create-or-update-comment@v4
251+
uses: peter-evans/create-or-update-comment@v5
252252
with:
253253
token: ${{ secrets.PAT }}
254254
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -264,7 +264,7 @@ Another option is to reply with a new comment containing a link to the run outpu
264264
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
265265
266266
- name: Create comment
267-
uses: peter-evans/create-or-update-comment@v4
267+
uses: peter-evans/create-or-update-comment@v5
268268
with:
269269
token: ${{ secrets.PAT }}
270270
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ outputs:
4141
error-message:
4242
description: 'Validation errors when using `workflow` dispatch.'
4343
runs:
44-
using: 'node20'
44+
using: 'node24'
4545
main: 'dist/index.js'
4646
branding:
4747
icon: 'target'

dist/index.js

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -293,24 +293,41 @@ class GitHubHelper {
293293
};
294294
}
295295
getActorPermission(repo, actor) {
296+
var _a;
296297
return __awaiter(this, void 0, void 0, function* () {
297-
// https://docs.github.com/en/graphql/reference/enums#repositorypermission
298-
// https://docs.github.com/en/graphql/reference/objects#repositorycollaboratoredge
299-
// Returns 'READ', 'TRIAGE', 'WRITE', 'MAINTAIN', 'ADMIN'
300-
const query = `query CollaboratorPermission($owner: String!, $repo: String!, $collaborator: String) {
301-
repository(owner:$owner, name:$repo) {
302-
collaborators(login: $collaborator) {
303-
edges {
304-
permission
305-
}
306-
}
307-
}
308-
}`;
309-
const collaboratorPermission = yield this.octokit.graphql(query, Object.assign(Object.assign({}, repo), { collaborator: actor }));
310-
core.debug(`CollaboratorPermission: ${(0, util_1.inspect)(collaboratorPermission.repository.collaborators.edges)}`);
311-
return collaboratorPermission.repository.collaborators.edges.length > 0
312-
? collaboratorPermission.repository.collaborators.edges[0].permission.toLowerCase()
313-
: 'none';
298+
// Use the REST API approach which can detect both direct and team-based permissions
299+
// This is more reliable than the GraphQL approach for team permissions and works better with default GITHUB_TOKEN
300+
try {
301+
const { data: collaboratorPermission } = yield this.octokit.rest.repos.getCollaboratorPermissionLevel(Object.assign(Object.assign({}, repo), { username: actor }));
302+
const permissions = (_a = collaboratorPermission.user) === null || _a === void 0 ? void 0 : _a.permissions;
303+
core.debug(`REST API collaborator permission: ${(0, util_1.inspect)(permissions)}`);
304+
// Use the detailed permissions object to get the highest permission level
305+
if (permissions) {
306+
// Check permissions in order of highest to lowest
307+
if (permissions.admin) {
308+
return 'admin';
309+
}
310+
else if (permissions.maintain) {
311+
return 'maintain';
312+
}
313+
else if (permissions.push) {
314+
return 'write';
315+
}
316+
else if (permissions.triage) {
317+
core.debug(`User ${actor} has triage permission via REST API`);
318+
return 'triage';
319+
}
320+
else if (permissions.pull) {
321+
core.debug(`User ${actor} has read permission via REST API`);
322+
return 'read';
323+
}
324+
}
325+
return 'none';
326+
}
327+
catch (error) {
328+
core.debug(`REST API permission check failed: ${utils.getErrorMessage(error)}`);
329+
return 'none';
330+
}
314331
});
315332
}
316333
tryAddReaction(repo, commentId, reaction) {
@@ -350,7 +367,8 @@ class GitHubHelper {
350367
}
351368
createWorkflowDispatch(cmd, clientPayload) {
352369
return __awaiter(this, void 0, void 0, function* () {
353-
const workflow = `${cmd.command}${cmd.event_type_suffix}.yml`;
370+
const workflowName = `${cmd.command}${cmd.event_type_suffix}`;
371+
const workflow = yield this.getWorkflow(cmd.repository, workflowName);
354372
const slashCommand = clientPayload.slash_command;
355373
const ref = slashCommand.args.named.ref
356374
? slashCommand.args.named.ref
@@ -370,6 +388,20 @@ class GitHubHelper {
370388
core.info(`Command '${cmd.command}' dispatched to workflow '${workflow}' in '${cmd.repository}'`);
371389
});
372390
}
391+
getWorkflow(repository, workflowName) {
392+
return __awaiter(this, void 0, void 0, function* () {
393+
core.debug(`Getting workflow ${workflowName} for repository ${repository}`);
394+
const { data: workflows } = yield this.octokit.rest.actions.listRepoWorkflows(Object.assign({}, this.parseRepository(repository)));
395+
for (const workflow of workflows.workflows) {
396+
if (workflow.path === `${workflowName}.yml` ||
397+
workflow.path === `${workflowName}.yaml`) {
398+
core.debug(`Selecting workflow file ${workflow.path}`);
399+
return workflow.path;
400+
}
401+
}
402+
throw new Error(`Workflow ${workflowName} not found`);
403+
});
404+
}
373405
getDefaultBranch(repository) {
374406
return __awaiter(this, void 0, void 0, function* () {
375407
const { data: repo } = yield this.octokit.rest.repos.get(Object.assign({}, this.parseRepository(repository)));

docs/advanced-configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For example, the following basic configuration means that all commands must have
88

99
```yml
1010
- name: Slash Command Dispatch
11-
uses: peter-evans/slash-command-dispatch@v4
11+
uses: peter-evans/slash-command-dispatch@v5
1212
with:
1313
token: ${{ secrets.PAT }}
1414
commands: |
@@ -38,7 +38,7 @@ jobs:
3838
runs-on: ubuntu-latest
3939
steps:
4040
- name: Slash Command Dispatch
41-
uses: peter-evans/slash-command-dispatch@v4
41+
uses: peter-evans/slash-command-dispatch@v5
4242
with:
4343
token: ${{ secrets.PAT }}
4444
config: >
@@ -84,7 +84,7 @@ jobs:
8484
steps:
8585
- uses: actions/checkout@v3
8686
- name: Slash Command Dispatch
87-
uses: peter-evans/slash-command-dispatch@v4
87+
uses: peter-evans/slash-command-dispatch@v5
8888
with:
8989
token: ${{ secrets.PAT }}
9090
config-from-file: .github/slash-command-dispatch.json

docs/examples.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
5151
# Add reaction to the comment
5252
- name: Add reaction
53-
uses: peter-evans/create-or-update-comment@v4
53+
uses: peter-evans/create-or-update-comment@v5
5454
with:
5555
token: ${{ secrets.PAT }}
5656
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -111,7 +111,7 @@ jobs:
111111

112112
# Add reaction to the comment
113113
- name: Add reaction
114-
uses: peter-evans/create-or-update-comment@v4
114+
uses: peter-evans/create-or-update-comment@v5
115115
with:
116116
token: ${{ secrets.PAT }}
117117
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -158,7 +158,7 @@ jobs:
158158
git push
159159
160160
- name: Add reaction
161-
uses: peter-evans/create-or-update-comment@v4
161+
uses: peter-evans/create-or-update-comment@v5
162162
with:
163163
token: ${{ secrets.PAT }}
164164
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -204,7 +204,7 @@ jobs:
204204
git push --force-with-lease
205205
206206
- name: Update comment
207-
uses: peter-evans/create-or-update-comment@v4
207+
uses: peter-evans/create-or-update-comment@v5
208208
with:
209209
token: ${{ secrets.PAT }}
210210
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -218,7 +218,7 @@ jobs:
218218
runs-on: ubuntu-latest
219219
steps:
220220
- name: Update comment
221-
uses: peter-evans/create-or-update-comment@v4
221+
uses: peter-evans/create-or-update-comment@v5
222222
with:
223223
token: ${{ secrets.PAT }}
224224
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -279,7 +279,7 @@ jobs:
279279
git push
280280
281281
- name: Add reaction
282-
uses: peter-evans/create-or-update-comment@v4
282+
uses: peter-evans/create-or-update-comment@v5
283283
with:
284284
token: ${{ secrets.PAT }}
285285
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -301,7 +301,7 @@ jobs:
301301
runs-on: ubuntu-latest
302302
steps:
303303
- name: Update comment
304-
uses: peter-evans/create-or-update-comment@v4
304+
uses: peter-evans/create-or-update-comment@v5
305305
with:
306306
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
307307
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Follow this guide to get started with a working `/example` command.
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Add reaction
22-
uses: peter-evans/create-or-update-comment@v4
22+
uses: peter-evans/create-or-update-comment@v5
2323
with:
2424
token: ${{ secrets.PAT }}
2525
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
@@ -56,7 +56,7 @@ Command processing setup is complete! Now we need to setup command dispatch for
5656
runs-on: ubuntu-latest
5757
steps:
5858
- name: Slash Command Dispatch
59-
uses: peter-evans/slash-command-dispatch@v4
59+
uses: peter-evans/slash-command-dispatch@v5
6060
with:
6161
token: ${{ secrets.PAT }}
6262
commands: example

0 commit comments

Comments
 (0)