Skip to content

Commit 563e237

Browse files
authored
Docathon: Add workflow to assign user on comment (#19294)
This workflow assigns a user to an issue when a comment containing '/assigntome' is made, provided the issue has the 'docathon-2026' label. cc @mergennachin @AlannaBurke
1 parent a8ce9ce commit 563e237

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Assign User on Comment
2+
3+
on:
4+
workflow_dispatch:
5+
issue_comment:
6+
types: [created]
7+
8+
jobs:
9+
assign:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write
13+
steps:
14+
- name: Check for "/assigntome" in comment
15+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
with:
19+
script: |
20+
const issueComment = context.payload.comment.body;
21+
const assignRegex = /\/assigntome/i;
22+
if (assignRegex.test(issueComment)) {
23+
const assignee = context.payload.comment.user.login;
24+
const issueNumber = context.payload.issue.number;
25+
try {
26+
const { data: issue } = await github.rest.issues.get({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
issue_number: issueNumber
30+
});
31+
const hasLabel = issue.labels.some(label => label.name === 'docathon-2026');
32+
if (hasLabel) {
33+
if (issue.assignee !== null) {
34+
await github.rest.issues.createComment({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
issue_number: issueNumber,
38+
body: "The issue is already assigned. Please pick an opened and unnasigned issue with the [docathon-2026 label](https://github.com/pytorch/executorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-2026)"
39+
});
40+
} else {
41+
await github.rest.issues.addAssignees({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
issue_number: issueNumber,
45+
assignees: [assignee]
46+
});
47+
}
48+
} else {
49+
const commmentMessage = "This issue does not have the correct label. Please pick an opened and unnasigned issue with the [docathon-2026 label](https://github.com/pytorch/executorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-2026)";
50+
await github.rest.issues.createComment({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
issue_number: issueNumber,
54+
body: commmentMessage
55+
});
56+
}
57+
} catch (error) {
58+
console.error(error);
59+
}
60+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Docathon Labels Sync
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, edited]
6+
branches: [main]
7+
8+
jobs:
9+
check-labels:
10+
if: github.repository_owner == 'pytorch'
11+
runs-on: ubuntu-latest
12+
permissions:
13+
issues: write
14+
pull-requests: write
15+
steps:
16+
- name: Check out the repo
17+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
with:
19+
fetch-depth: 1
20+
- name: Set up Python
21+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
22+
with:
23+
python-version: 3.x
24+
- name: Install dependencies
25+
run: |
26+
pip install requests==2.32.3
27+
pip install PyGithub==2.3.0
28+
- name: Run Python script
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: python ./.github/scripts/docathon-label-sync.py ${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)