Skip to content
105 changes: 105 additions & 0 deletions .github/workflows/application-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Application Flow

on:
issues:
types: [opened]
pull_request:
types: [closed]

jobs:
ask-for-pr:
if: github.event_name == 'issues'
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/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);
}

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/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}`);
}
}
1 change: 1 addition & 0 deletions .github/workflows/application-follow-up-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi @${candidate} — thanks for applying! Please add your profile by opening a pull request that adds a JSON file with your profile under profile-submission.json. In your PR description include "resolves: #${issue_number}" or "closes: #${issue_number}" so we can link it to this application. Once your PR is merged we'll reopen this issue and ask you to proceed with the trial task.
1 change: 1 addition & 0 deletions .github/workflows/application-merged-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi @${user} — your profile PR was merged. Please proceed with the trial task via link: https://github.com/holdex/trial/issues?q=is%3Aissue%20state%3Aopen%20label%3Atrial-task
Loading