diff --git a/.github/workflows/create_issue_from_discussion.yml b/.github/workflows/create_issue_from_discussion.yml new file mode 100644 index 0000000..57e1930 --- /dev/null +++ b/.github/workflows/create_issue_from_discussion.yml @@ -0,0 +1,41 @@ +name: Create issue from discussion + +on: + discussion: + types: [labeled] + +jobs: + create-issue: + 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 + 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; + + const repoMap = { + 'explorer': 'stampchain-io/BTCStampsExplorer', + 'indexer': 'stampchain-io/btc_stamps', + }; + + if (repoMap[label]) { + const [owner, repo] = repoMap[label].split('/'); + 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'] + }); + } \ No newline at end of file diff --git a/.github/workflows/new_discussion_to_project.yml b/.github/workflows/new_discussion_to_project.yml deleted file mode 100644 index 42edef6..0000000 --- a/.github/workflows/new_discussion_to_project.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Add new discussions to project - -on: - discussion: - types: [created, reopened] - -jobs: - add-to-project: - name: Add discussion to project - 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: Add to project - uses: actions/github-script@v7 - with: - github-token: ${{ steps.generate_token.outputs.token }} - script: | - const projectId = 'PVT_kwDOCAGLAM4Anzfw'; - const discussionId = context.payload.discussion.node_id; - - console.log(`Adding discussion ${discussionId} to project ${projectId}`); - - try { - const response = await github.graphql(` - mutation($projectId: ID!, $contentId: ID!) { - addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) { - item { - id - } - } - } - `, { - projectId: projectId, - contentId: discussionId - }); - - console.log('Added to project:', JSON.stringify(response, null, 2)); - } catch (error) { - console.error('Error:', error.message); - if (error.errors) { - error.errors.forEach((e, i) => console.error(`Error ${i + 1}:`, e)); - } - core.setFailed(error.message); - }