From e20e50d1283b70d02430da6ee0e866d9a37b7739 Mon Sep 17 00:00:00 2001 From: Armando Banuelos Date: Thu, 11 Apr 2024 16:08:10 -0700 Subject: [PATCH 1/2] feat: creating workflow to sync github issues to Jira --- .github/workflows/sync-issues-with-jira.yml | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/sync-issues-with-jira.yml diff --git a/.github/workflows/sync-issues-with-jira.yml b/.github/workflows/sync-issues-with-jira.yml new file mode 100644 index 000000000..674ee9ac9 --- /dev/null +++ b/.github/workflows/sync-issues-with-jira.yml @@ -0,0 +1,73 @@ +name: sync_issues_with_jira +on: + issues: + types: [opened] + +jobs: + generate-issue-link: + runs-on: ubuntu-latest + steps: + - name: Sync issue with Jira + uses: actions/github-script@v4 + env: + JIRA_DOMAIN: ${{ secrets.JIRA_DOMAIN }} + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fetch = require('node-fetch'); + const repoName = context.payload.repository.full_name; + const issueNumber = context.payload.issue.number; + const issueTitle = context.payload.issue.title; + const issueLink = `https://github.com/${repoName}/issues/${issueNumber}`; + console.log(`Issue Title: ${issueTitle}`); + console.log(`Issue Link: ${issueLink}`); + + const bodyData = ` + "fields": { + "description": { + "content": [ + { + "content": [ + { + "text": "${issueLink}", + "type": "text" + } + ], + "type": "paragraph" + } + ], + "type": "doc", + "version": 1 + }, + "summary": "${issueTitle}", + "issuetype": { + "id": "10001" + }, + "project": { + "key": "SCENIC" + } + } + `; + + fetch(`https://${JIRA_DOMAIN}.atlassian.net/rest/api/3/issue`, { + method: 'POST', + headers: { + 'Authorization': `Basic ${Buffer.from( + `${JIRA_EMAIL}:{JIRA_API_TOKEN}` + ).toString('base64')}`, + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: bodyData + }) + .then(response => { + console.log( + `Response: ${response.status} ${response.statusText}` + ); + return response.text(); + }) + .then(text => console.log(text)) + .catch(err => console.error(err)); + From 1c9a2c062295085a254619038401b7d3cca575e0 Mon Sep 17 00:00:00 2001 From: Armando Banuelos Date: Thu, 11 Apr 2024 16:37:41 -0700 Subject: [PATCH 2/2] feat: breaking test into two steps --- .github/workflows/sync-issues-with-jira.yml | 121 +++++++++----------- 1 file changed, 56 insertions(+), 65 deletions(-) diff --git a/.github/workflows/sync-issues-with-jira.yml b/.github/workflows/sync-issues-with-jira.yml index 674ee9ac9..c07924afa 100644 --- a/.github/workflows/sync-issues-with-jira.yml +++ b/.github/workflows/sync-issues-with-jira.yml @@ -4,70 +4,61 @@ on: types: [opened] jobs: - generate-issue-link: - runs-on: ubuntu-latest - steps: - - name: Sync issue with Jira - uses: actions/github-script@v4 - env: - JIRA_DOMAIN: ${{ secrets.JIRA_DOMAIN }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const fetch = require('node-fetch'); - const repoName = context.payload.repository.full_name; - const issueNumber = context.payload.issue.number; - const issueTitle = context.payload.issue.title; - const issueLink = `https://github.com/${repoName}/issues/${issueNumber}`; - console.log(`Issue Title: ${issueTitle}`); - console.log(`Issue Link: ${issueLink}`); - - const bodyData = ` - "fields": { - "description": { - "content": [ - { - "content": [ - { - "text": "${issueLink}", - "type": "text" + generate-issue-link: + runs-on: ubuntu-latest + steps: + - name: Get issue details + id: get_issue_details + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GH_ACCESS_TOKEN }} + script: | + const repoName = context.payload.repository.full_name; + const issueNumber = context.payload.issue.number; + const issueTitle = context.payload.issue.title; + const issueLink = `https://github.com/${repoName}/issues/${issueNumber}`; + console.log(`::set-output name=issueTitle::${issueTitle}`); + console.log(`::set-output name=issueLink::${issueLink}`); + + - name: Create Jira Ticket + env: + JIRA_DOMAIN: ${{ secrets.JIRA_DOMAIN }} + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} + ISSUE_TITLE: ${{ steps.get_issue_details.outputs.issueTitle }} + ISSUE_LINK: ${{ steps.get_issue_details.outputs.issueLink }} + run: | + echo "Issue Title: $ISSUE_TITLE" + echo "Issue Link: $ISSUE_LINK" + + curl --request POST \ + --url "https://$JIRA_DOMAIN.atlassian.net/rest/api/3/issue" \ + --user "$JIRA_EMAIL:$JIRA_API_TOKEN" \ + --header "Accept: application/json" \ + --header "Content-Type: application/json" \ + --data '{ + "fields": { + "description": { + "content": [ + { + "content": [ + { + "text": "'"$ISSUE_LINK"'", + "type": "text" + } + ], + "type": "paragraph" + } + ], + "type": "doc", + "version": 1 + }, + "summary": "'"$ISSUE_TITLE"'", + "issuetype": { + "id": "10001" + }, + "project": { + "key": "SCENIC" } - ], - "type": "paragraph" } - ], - "type": "doc", - "version": 1 - }, - "summary": "${issueTitle}", - "issuetype": { - "id": "10001" - }, - "project": { - "key": "SCENIC" - } - } - `; - - fetch(`https://${JIRA_DOMAIN}.atlassian.net/rest/api/3/issue`, { - method: 'POST', - headers: { - 'Authorization': `Basic ${Buffer.from( - `${JIRA_EMAIL}:{JIRA_API_TOKEN}` - ).toString('base64')}`, - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: bodyData - }) - .then(response => { - console.log( - `Response: ${response.status} ${response.statusText}` - ); - return response.text(); - }) - .then(text => console.log(text)) - .catch(err => console.error(err)); - + }' \ No newline at end of file