[Project] SIP Investment Calculator #1545
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 isBotUser(u) { | |
| return u === 'github-actions[bot]' || u.endsWith('[bot]'); | |
| } | |
| 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); | |
| } | |
| 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} You have been assigned to this issue.`, | |
| '', | |
| 'You can begin working on it whenever you are ready. Please keep all changes inside your own project folder and do not modify any files outside it.', | |
| ].join('\n'), | |
| }); | |
| } | |
| } | |
| } else if (event === 'issues' && action === 'opened') { | |
| const label = chooseLabel(issueTitle, issueBody); | |
| await github.rest.issues.addLabels({ | |
| owner, repo, issue_number: issueNum, labels: [label], | |
| }); | |
| if ( | |
| triggerUser !== repoOwner && | |
| !isBotUser(triggerUser) && | |
| !(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} You have been automatically assigned to this issue.`, | |
| '', | |
| 'You can start working on it whenever you are ready. Please ensure all changes are inside your project folder only.', | |
| ].join('\n'), | |
| }); | |
| } | |
| } else if (event === 'issues' && action === 'assigned') { | |
| if (!isBotUser(triggerUser)) { | |
| const assignee = context.payload.assignee?.login || triggerUser; | |
| await github.rest.issues.createComment({ | |
| owner, repo, issue_number: issueNum, | |
| body: `@${assignee} You have been assigned to this issue. Good luck and happy contributing.`, | |
| }); | |
| } | |
| } |