Add login check embed to companion command #19
This file contains 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: Draft | |
on: | |
issues: | |
types: [assigned] | |
jobs: | |
draft: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { owner, repo, number: issueNumber } = context.issue; | |
const req = await github.issues.get({ | |
owner, | |
repo, | |
issue_number: issueNumber | |
}); | |
const issue = req.data | |
const labels = issue.labels; | |
const typeLabel = labels.find(label => label.name.startsWith('Type')) || { name: '' } | |
const serviceLabel = labels.find(label => label.name.startsWith('Service')) | |
const service = serviceLabel ? serviceLabel.name.split(':')[1].trim().toLowerCase() : null | |
const dod = issue.body.split('### Definition of Done')[1].split('- ').slice(3) | |
let type = 'patch'; | |
if (typeLabel.name === 'Type: Bug') { | |
type = 'fix'; | |
} else if (typeLabel.name === 'Type: New Feature') { | |
type = 'feat'; | |
} else if (typeLabel.name === 'Type: Refactor') { | |
type = 'refactor'; | |
} | |
const branchName = `${type}${service ? `/${service}` : ''}/${issueNumber}` | |
const baseBranchRef = await github.git.getRef({ | |
owner, | |
repo, | |
ref: 'heads/master' | |
}) | |
const newBranchRef = await github.git.createRef({ | |
owner, | |
repo, | |
ref: `refs/heads/${branchName}`, | |
sha: baseBranchRef.data.object.sha | |
}) | |
const currentCommit = await github.git.getCommit({ | |
owner, | |
repo, | |
commit_sha: newBranchRef.data.object.sha | |
}) | |
const newCommit = await github.git.createCommit({ | |
owner, | |
repo, | |
message: 'chore: Prime new branch', | |
tree: currentCommit.data.tree.sha, | |
parents: [currentCommit.data.sha], | |
}); | |
await github.git.updateRef({ | |
owner, | |
repo, | |
ref: `heads/${branchName}`, | |
sha: newCommit.data.sha, | |
}) | |
const pr = await github.pulls.create({ | |
owner, | |
repo, | |
title: `${type}${service ? `(${service})` : ''}: ${issue.title}`, | |
head: branchName, | |
base: 'master', | |
draft: true, | |
body: `### Related Issues <!-- Use "Resolves #number" to close the issues that this PR addresses --> | |
Resolves #${issueNumber} | |
### Definition of Done <!-- Please add all DoDs and mark them as completed --> | |
- [ ] Acceptance tests are passed | |
- [ ] Every user/service-facing endpoint is covered in automated tests | |
- [ ] Every non-trivial function is unit tested | |
- [ ] If something takes more than a minute to test manually, it must be automated | |
- [ ] Every use case is logged | |
- [ ] Every user input is sanitized or validated | |
- [ ] Approval of the product owner and code owners | |
${dod.map(d => `- [ ] ${d}`).join()}` | |
}); | |
await github.issues.addAssignees({ | |
owner, | |
repo, | |
issue_number: pr.data.number, | |
assignees: [issue.assignee.login] | |
}) |