You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Create a new GitHub Actions workflow to automatically assign issues
- Workflow triggers on issue comment creation
- Assigns the issue to the commenter when they type "/assign"
- Includes checks for bot users, closed issues, and existing assignments
- Sends a comment to the issue if assignment fails or if the issue is closed
if (issue.assignees && issue.assignees.some(a => a.login === commenter)) {
36
+
console.log(`Issue #${issueNumber} is already assigned to @${commenter}. No action needed.`);
37
+
return;
38
+
}
39
+
if (issue.state === 'closed') {
40
+
console.log(`Issue #${issueNumber} is closed. No assignment will be made.`);
41
+
await github.rest.issues.createComment({
42
+
owner: repoOwner,
43
+
repo: repoName,
44
+
issue_number: issueNumber,
45
+
body: `Hi @${commenter}, issue #${issueNumber} is closed and cannot be assigned.`
46
+
});
47
+
return;
48
+
}
49
+
try {
50
+
await github.rest.issues.addAssignees({
51
+
owner: repoOwner,
52
+
repo: repoName,
53
+
issue_number: issueNumber,
54
+
assignees: [commenter]
55
+
});
56
+
console.log(`Successfully assigned issue #${issueNumber} to @${commenter}.`);
57
+
} catch (error) {
58
+
console.error(`Error assigning issue #${issueNumber} to @${commenter}:`, error);
59
+
await github.rest.issues.createComment({
60
+
owner: repoOwner,
61
+
repo: repoName,
62
+
issue_number: issueNumber,
63
+
body: `Hi @${commenter}, I encountered an error trying to assign you to issue #${issueNumber}. Please check permissions or assign manually. \nError: ${error.message}`
64
+
});
65
+
}
66
+
} else {
67
+
console.log(`Comment by @${commenter} on issue #${issueNumber} was not an "/assign" command. Body: "${context.payload.comment.body.trim()}"`);
0 commit comments