-
Notifications
You must be signed in to change notification settings - Fork 1.4k
122 lines (103 loc) · 5.43 KB
/
Copy pathauto_assign.yml
File metadata and controls
122 lines (103 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Automated runs commented out, see https://github.com/commons-app/apps-android-commons/issues/6576#issuecomment-3618798882
# Added workflow_dispatch temporarily for having a syntactically correct workflow file
on:
workflow_dispatch:
# issue_comment:
# types: [created]
permissions:
issues: write
models: read
concurrency:
group: auto-assign-${{ github.event.issue.number || github.run_id }}
cancel-in-progress: true
jobs:
auto-assign:
runs-on: ubuntu-latest
steps:
- name: Check if requesting assignment
uses: actions/ai-inference@v1
id: check-request
with:
prompt: |
You are a project management assistant. Determine if the user is explicitly asking to be assigned to THIS specific GitHub issue.
ISSUE CONTEXT:
Title: ${{ github.event.issue.title }}
Description: ${{ github.event.issue.body }}
USER COMMENT:
"${{ github.event.comment.body }}"
STRICT RULES:
1. Respond "yes" ONLY if the user wants to work on the task described in the ISSUE CONTEXT.
2. Respond "no" if the user is offering general help, suggesting new features, or discussing unrelated topics.
3. Respond "no" if the user is just answering a question or providing feedback.
4. If they say "I can help" but are talking about a different topic than the issue description, respond "no".
Respond with only "yes" or "no".
model: openai/gpt-4o-mini
- name: Handle assignment
if: steps.check-request.outputs.response == 'yes'
uses: actions/github-script@v7
with:
script: |
const commenter = context.actor;
const authorAssociation = context.payload.comment.author_association;
const isFirstTime = authorAssociation === 'FIRST_TIME_CONTRIBUTOR' || authorAssociation === 'NONE';
const welcomeMessage = `\n\nSince you're new here, a huge welcome to the team! ❤️ Feel free to check out our welcome guide to get started: https://github.com/commons-app/commons-app-documentation/blob/master/android/Volunteers-welcome!.md`;
// Check if the issue is already assigned
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
if (issue.data.assignees.length > 0) {
let body = `Hi @${commenter}! Thanks for reaching out. It looks like someone is already working on this one at the moment. `;
body += `\n\nNo worries, though-there are plenty of other ways to help! You can find more open issues here: https://github.com/commons-app/apps-android-commons/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20no%3Aassignee%20-label%3A%22low%20priority%22%20-label%3Adebated%20-label%3Aupstream`;
// Only show the welcome message to new contributors
if (isFirstTime) body += welcomeMessage;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
return;
}
// Check commenter's existing assignments and PR's
const assignedIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
assignee: commenter,
state: 'open'
});
const pullRequests = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
creator: commenter,
state: 'open'
});
// Decision logic:
// - If no assigned issues: safe to assign
// - If has assigned issues and has open PR: safe to assign (they are waiting for review)
// - If has assigned issues but no pr's: block (they need to finish current work first)
if (assignedIssues.data.length === 0 || pullRequests.data.length > 0) {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: [commenter]
});
// Post the confirmation comment
let body = `Hi @${commenter}! You have been assigned to this issue. ✨`;
if (isFirstTime) body += welcomeMessage;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Hi @${commenter}! It looks like you're already busy with another open task. To keep things moving and make sure everyone gets a chance to help out, we usually recommend wrapping up your current work before starting something new. \n\nOnce you've submitted a PR for your current task, we'd be happy to help you get started on this one! ✨`
});
}