HR: Other: Gerard Möller #19
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: Application Flow | |
| on: | |
| issues: | |
| types: [opened] | |
| pull_request: | |
| types: [closed] | |
| jobs: | |
| ask-for-pr: | |
| if: github.event_name == 'issues' && contains(github.event.issue.labels.*.name, 'job-application') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Comment with PR instructions | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const issue = context.payload.issue; | |
| const candidate = issue.user.login; | |
| const workspace = process.env.GITHUB_WORKSPACE; | |
| const commentBody = fs.readFileSync(path.join(workspace, '.github/workflows/job-application-follow-up-body.md'), 'utf8') | |
| .replace('${candidate}', candidate) | |
| .replaceAll('${issue_number}', issue.number); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.issue.number, | |
| body: commentBody | |
| }); | |
| try { | |
| await github.rest.issues.addLabels({ ...context.repo, issue_number: issue.number, labels: ['job-application'] }); | |
| } catch (e) { | |
| console.log('Could not add label:', e.message); | |
| } | |
| const positionLabelMap = { | |
| 'Partnership Lead': 'position/partnership-lead', | |
| 'Partner (Entrepreneur in Residence)': 'position/partner', | |
| 'Marketing Maestro (Head of Marketing)': 'position/marketing-maestro', | |
| 'UX/UI Designer': 'position/ux-ui-designer', | |
| 'UX/UI Engineer': 'position/ux-ui-engineer', | |
| 'Full-Stack Engineer': 'position/full-stack-engineer', | |
| 'DevOps Engineer': 'position/devops-engineer', | |
| 'GoLang Engineer': 'position/golang-engineer', | |
| 'Data Scientist': 'position/data-scientist', | |
| 'Python Engineer': 'position/python-engineer', | |
| 'Developer Relations (DevRel)': 'position/devrel', | |
| 'Senior Smart Contract Developer': 'position/smart-contract-developer', | |
| 'Executive Assistant': 'position/executive-assistant', | |
| 'Actuarial Advisor': 'position/actuarial-advisor', | |
| 'Other': 'position/other', | |
| }; | |
| const body = issue.body || ''; | |
| const positionMatch = body.match(/###\s*Application Position\s*\n+([^\n]+)/); | |
| if (positionMatch) { | |
| const positionLabel = positionLabelMap[positionMatch[1].trim()]; | |
| if (positionLabel) { | |
| try { | |
| await github.rest.issues.addLabels({ ...context.repo, issue_number: issue.number, labels: [positionLabel] }); | |
| } catch (e) { | |
| if (e.status === 422) { | |
| await github.rest.issues.createLabel({ ...context.repo, name: positionLabel, color: '0075ca' }); | |
| await github.rest.issues.addLabels({ ...context.repo, issue_number: issue.number, labels: [positionLabel] }); | |
| } else { | |
| console.log('Could not add position label:', e.message); | |
| } | |
| } | |
| } | |
| } | |
| const firstNameMatch = body.match(/###\s*First Name\s*\n+([^\n]+)/); | |
| const lastNameMatch = body.match(/###\s*Last Name\s*\n+([^\n]+)/); | |
| const position = positionMatch ? positionMatch[1].trim() : null; | |
| const firstName = firstNameMatch ? firstNameMatch[1].trim() : null; | |
| const lastName = lastNameMatch ? lastNameMatch[1].trim() : null; | |
| if (position && firstName && lastName) { | |
| await github.rest.issues.update({ | |
| ...context.repo, | |
| issue_number: issue.number, | |
| title: `HR: ${position}: ${firstName} ${lastName}` | |
| }); | |
| } | |
| reopen-issue: | |
| if: github.event_name == 'pull_request' && github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Reopen linked issues and ask to proceed | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const owner = context.repo.owner.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |
| const repo = context.repo.repo.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |
| const prBody = context.payload.pull_request.body || ''; | |
| const regex = new RegExp( | |
| `(?:resolves|closes):?\\s*(?:#(\\d+)|https:\\/\\/github\\.com\\/${owner}\\/${repo}\\/issues\\/(\\d+))`, | |
| 'mi' | |
| ); | |
| let remaining = prBody; | |
| const matches = []; | |
| while (true) { | |
| const match = regex.exec(remaining); | |
| if (!match) break; | |
| matches.push(match); | |
| // move forward in the string manually | |
| remaining = remaining.slice(match.index + match[0].length); | |
| } | |
| // Extract the numbers and remove duplicates | |
| const issueNumbers = [...new Set(matches.map(m => parseInt(m[1] || m[2], 10)))]; | |
| // use md file | |
| const workspace = process.env.GITHUB_WORKSPACE; | |
| const user = context.payload.pull_request.user.login | |
| const commentBody = fs.readFileSync(path.join(workspace, '.github/workflows/job-application-merged-body.md'), 'utf8') | |
| .replace('${user}', user); | |
| for (const issue_number of issueNumbers) { | |
| try { | |
| // The actual command to reopen | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue_number, | |
| state: 'open' | |
| }); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue_number, | |
| body: commentBody | |
| }); | |
| } catch (error) { | |
| console.log(`Could not reopen issue #${issue_number}: ${error.message}`); | |
| } | |
| } |