diff --git a/.github/workflows/application-flow.yml b/.github/workflows/application-flow.yml new file mode 100644 index 0000000..bfaa1ac --- /dev/null +++ b/.github/workflows/application-flow.yml @@ -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}`); + } + } diff --git a/.github/workflows/application-follow-up-body.md b/.github/workflows/application-follow-up-body.md new file mode 100644 index 0000000..0841acb --- /dev/null +++ b/.github/workflows/application-follow-up-body.md @@ -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. diff --git a/.github/workflows/application-merged-body.md b/.github/workflows/application-merged-body.md new file mode 100644 index 0000000..5613695 --- /dev/null +++ b/.github/workflows/application-merged-body.md @@ -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