Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add properties #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions workflow-templates/jira-issues-integration-properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Jira Issues Integration",
"description": "This Workflow performs real-time synchronization of Issues from Github to Jira.",
"categories": [
"Automation"
]
}
137 changes: 137 additions & 0 deletions workflow-templates/jira-issues-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: jira issues Integration

# Triggers to run the workflow automatic when issues opened, closed and created.
on:
issues:
types:
- opened
- closed
issue_comment:
types:
- created

# Building variables based on github events.
jobs:
Jira_Integration:
runs-on: ubuntu-latest
steps:
- name: Get Issue Details
id: issue_details
run: |
echo "${{ github.event.issue.title }}" >> summary.txt
echo "${{ github.event.issue.body }}" >> description.txt
echo "${{ github.event.comment.body }}" >> event.txt
echo -n "${{ secrets.ATLASSIAN_USER }}:${{ secrets.ATLASSIAN_TOKEN }}" | base64 -w0 | tr -d '\n' >> auth_token.txt

- name: Create Issue in Jira
if: ${{ github.event_name == 'issues' && github.event.action == 'opened' }}
id: create_jira_issue
run: |
summary=$(cat summary.txt)
description=$(cat description.txt)
description=$(echo "${description}" | tr -d '\n' | tr -d '\r')
token=$(cat auth_token.txt)

response=$(curl -v --request POST \
--url 'https://contameupag.atlassian.net/rest/api/3/issue' \
--header "Authorization: Basic $token" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"fields": {
"project": {
"key": "GIT"
},
"summary": "'"${summary}"'",
"description": {
"content": [
{
"content": [
{
"text": "'"${description}"'",
"type": "text"
}
],
"type": "paragraph"
}
],
"type": "doc",
"version": 1
},
"issuetype": {
"name": "Task"
}
}
}')

- name: Get Issue ID
if: ${{ (github.event_name == 'issues' || github.event_name == 'issue_comment') && github.event.action != 'opened' }}
id: obter_issue_id
run: |
summary=$(cat summary.txt)
description=$(cat description.txt)
token=$(cat auth_token.txt)

encoded_summary=$(echo "$summary" | jq -s -R -r @uri)
encoded_description=$(echo "$description" | jq -s -R -r @uri)

response=$(curl --request GET \
--url "https://contameupag.atlassian.net/rest/api/3/search?jql=summary~'${encoded_summary}'&description='${encoded_description}'" \
--header "Authorization: Basic $token" \
--header 'Accept: application/json')

issue_id=$(echo "$response" | jq -r '.issues[0].id')
echo "$issue_id" >> id.txt
cat id.txt


- name: Add Comment to Jira Issue
if: ${{ github.event_name == 'issue_comment' && github.event.action == 'created' }}
id: Add_Comment
run: |
issue_id=$(cat id.txt)
issue_id="${issue_id%$cr}"

event=$(cat event.txt)
event=$(echo "${event}" | tr -d '\n' | tr -d '\r')

token=$(cat auth_token.txt)

response=$(curl -v --request POST \
--url "https://contameupag.atlassian.net/rest/api/3/issue/${issue_id}/comment" \
--header "Authorization: Basic $token" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"body": {
"content": [
{
"content": [
{
"text": "'"${event}"'",
"type": "text"
}
],
"type": "paragraph"
}
],
"type": "doc",
"version": 1
},
"visibility": {
"type": "role",
"value": "Membro do Time"
}
}')

- name: Close Issue
if: ${{ github.event_name == 'issues' && github.event.action == 'closed' }}
id: close_issue
run: |
issue_id=$(cat id.txt)
issue_id="${issue_id%$cr}"
token=$(cat auth_token.txt)

response=$(curl -v --request DELETE \
--url "https://contameupag.atlassian.net/rest/api/3/issue/${issue_id}" \
--header "Authorization: Basic $token")