Skip to content

Delete Repos Prepare: Issue #78 by @joshjohanning #32

Delete Repos Prepare: Issue #78 by @joshjohanning

Delete Repos Prepare: Issue #78 by @joshjohanning #32

name: delete-repos-prepare
run-name: 'Delete Repos Prepare: Issue #${{ github.event.issue.number }} by @${{ github.actor }}'
on:
issues:
types: [opened]
jobs:
delete-repos-prepare:
name: Prepare Migration
runs-on: ubuntu-latest
if: github.event_name == 'issues' &&
(github.event.action == 'opened') &&
contains(github.event.issue.labels.*.name, 'delete-repos')
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@v4
- name: Write GitHub context to log
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/delete-repos.yml
- name: Set env vars
run: |
echo "REPO_NAME=${{ steps.issue-parser.outputs.issueparser_repo_name }}" >> $GITHUB_ENV
echo "REPO_DESCRIPTION=${{ steps.issue-parser.outputs.issueparser_repo_description }}" >> $GITHUB_ENV
echo "REPO_VISIBILITY=${{ steps.issue-parser.outputs.issueparser_repo_visibility }}" >> $GITHUB_ENV
- name: Rename issue
uses: actions/github-script@v6
env:
REPOSITORIES: ${{ steps.issue-parser.outputs.issueparser_repositories }}
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
let repositories = process.env.REPOSITORIES.trim().split('\n');
let issueTitleRepo
if (repositories.length > 1) {
issueTitleRepo = `${repositories[0].trim()}...`;
} else {
issueTitleRepo = repositories[0].trim();
}
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
title: `Delete Repo(s): ${{ github.actor }} (${issueTitleRepo}) (Count: ${repositories.length})`
})
- name: Post prepare message
uses: actions/github-script@v6
env:
REPOSITORIES: ${{ steps.issue-parser.outputs.issueparser_repositories }}
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
let commentBody
commentBody = `👋 Thank you for opening this issue to delete repo(s), @${{ github.actor }}.
The following **${process.env.REPOSITORIES.trim().split('\n').length} repositories** have been parsed from your issue body:
\`\`\`
${process.env.REPOSITORIES}
\`\`\`
## 1. Approval
Someone from the @${process.env.GITHUB_REPOSITORY_OWNER}/approver-team team has to run the following command in order to proceed:
\`\`\`
/approve
\`\`\`
## 2. Delete the repo(s)
Add the following comment to this issue in order to delete the repo(s):
\`\`\`
/delete-repos
\`\`\`
`
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody.replace(/ +/g, '')
})
- name: Post failure message
if: ${{ failure() }}
uses: actions/github-script@v6
with:
script: |
let commentBody
commentBody = `😢 The issue body could not be parsed, @${{ github.actor }}. Please open a new issue using the issue template and ensure your formatting and line spacing remains untouched.`
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody.replace(/ +/g, '')
})