Create issue from discussion and update discussion #10
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: Create issue from discussion and update discussion | |
on: | |
discussion: | |
types: [labeled] | |
jobs: | |
create-issue-and-update-discussion: | |
if: contains(fromJson('["explorer", "indexer"]'), github.event.label.name) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate token | |
id: generate_token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{ secrets.APP_ID }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY }} | |
- name: Create issue and update discussion | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.generate_token.outputs.token }} | |
script: | | |
const label = context.payload.label.name; | |
const discussion = context.payload.discussion; | |
// Map labels to repositories | |
const repoMap = { | |
'explorer': 'stampchain-io/BTCStampsExplorer', | |
'indexer': 'stampchain-io/btc_stamps', | |
}; | |
if (repoMap[label]) { | |
const [owner, repo] = repoMap[label].split('/'); | |
// Create issue | |
const issue = await github.rest.issues.create({ | |
owner: owner, | |
repo: repo, | |
title: `Discussion: ${discussion.title}`, | |
body: `Created from discussion: ${discussion.html_url}\n\n${discussion.body}`, | |
labels: ['from-discussion'] | |
}); | |
// Update discussion with issue link | |
const issueUrl = issue.data.html_url; | |
const updatedBody = `${discussion.body}\n\n---\nIssue created: ${issueUrl}`; | |
await github.rest.discussions.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
discussion_number: discussion.number, | |
body: updatedBody | |
}); | |
console.log(`Issue created: ${issueUrl}`); | |
console.log(`Discussion updated: ${discussion.html_url}`); | |
} |