[Project] Digital Notebook #633
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Issue Automation | |
| on: | |
| issues: | |
| types: [opened, assigned] | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| issues: write | |
| jobs: | |
| manage-issues: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Process Issue Logic | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const issueNum = context.issue.number; | |
| const event = context.eventName; | |
| const action = context.payload.action; | |
| const triggerUser = context.payload.sender.login; | |
| const repoOwner = 'cu-sanjay'; | |
| function chooseLabel(title, body) { | |
| const text = `${title || ''} ${body || ''}`.toLowerCase(); | |
| if (/good first|good first issue|beginner|starter/.test(text)) { | |
| return 'good first issue'; | |
| } | |
| return 'enhancement'; | |
| } | |
| async function hasActiveAssignments(username) { | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner, | |
| repo, | |
| assignee: username, | |
| state: 'open' | |
| }); | |
| return issues.some(i => i.number !== issueNum); | |
| } | |
| function isBotUser(username) { | |
| return username === 'github-actions[bot]' || username.endsWith('[bot]'); | |
| } | |
| const issue = context.payload.issue; | |
| const issueTitle = issue.title || ''; | |
| const issueBody = issue.body || ''; | |
| if (event === 'issue_comment' && action === 'created' && !issue.pull_request) { | |
| const assignees = issue.assignees || []; | |
| if (assignees.length === 0 && triggerUser !== repoOwner && !isBotUser(triggerUser)) { | |
| if (!(await hasActiveAssignments(triggerUser))) { | |
| await github.rest.issues.addAssignees({ owner, repo, issue_number: issueNum, assignees: [triggerUser] }); | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number: issueNum, | |
| body: `@${triggerUser} assigned. You can start working on this. Please make sure you only work inside your project folder and make no changes to files outside the project directory.` | |
| }); | |
| } | |
| } | |
| } else if (event === 'issues' && action === 'opened') { | |
| const labels = ["NSoC'26"]; | |
| const secondaryLabel = chooseLabel(issueTitle, issueBody); | |
| labels.push(secondaryLabel); | |
| await github.rest.issues.addLabels({ owner, repo, issue_number: issueNum, labels }); | |
| if (triggerUser !== repoOwner && !isBotUser(triggerUser) && !(await hasActiveAssignments(triggerUser))) { | |
| await github.rest.issues.addAssignees({ owner, repo, issue_number: issueNum, assignees: [triggerUser] }); | |
| } | |
| } else if (event === 'issues' && action === 'assigned') { | |
| if (triggerUser !== 'github-actions[bot]') { | |
| const assignee = context.payload.assignee.login; | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number: issueNum, | |
| body: `@${assignee} you can start working on it. Best wishes and happy open-sourcing!` | |
| }); | |
| } | |
| } |