Skip to content

[LAB3] 312555001

[LAB3] 312555001 #1366

Workflow file for this run

name: PR automation
on:
pull_request_target:
types: [opened, reopened, edited, ready_for_review]
jobs:
labeler:
runs-on: ubuntu-latest
steps:
- name: Label PR
uses: actions/github-script@v5
with:
github-token: ${{ secrets.PAT }}
script: |
const { owner, repo, number: issue_number } = context.issue;
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
const title = pr.data.title;
const titleRegex = /^\[LAB(\d+)\] [a-zA-Z]?\d+$/;
const match = title.match(titleRegex);
let labNumberStr = undefined;
if (match) {
labNumberStr = match[1];
} else {
core.setFailed('PR title does not match the required format. Please use the format: [LAB#] <studentId>.');
}
const labelToAdd = `lab${labNumberStr}`;
if (labNumberStr) {
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] });
}
if (pr.data.base.ref === 'main') {
core.setFailed('The target branch cannot be main.');
}
if (labNumberStr < 3 && pr.data.head.ref !== pr.data.base.ref) {
core.setFailed('The source branch and target branch must be the same.');
}
if (labNumberStr >= 3 && pr.data.head.ref !== labelToAdd) {
core.setFailed(`The source branch must be '${labelToAdd}'`);
}
checklist-check:
runs-on: ubuntu-latest
steps:
- name: Check PR description
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number: issue_number } = context.issue;
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
const body = pr.data.body;
const checkboxes = body.match(/^ ?(-|\*) \[[x ]\]/gmi);
if (!checkboxes || checkboxes.length !== 5) {
core.setFailed('The PR description must contain exactly 5 checkboxes.');
}
const unchecked = body.match(/^ ?(-|\*) \[ \]/gm);
if (unchecked && unchecked.length > 0) {
core.setFailed(`There are ${unchecked.length} unchecked item(s) in the PR description.`);
}