Skip to content

Commit e0c93d6

Browse files
authored
Merge pull request #51 from OneSignal/user-api-updates
chore: add github-to-asana workflow
2 parents 9c9348d + 07417ce commit e0c93d6

File tree

6 files changed

+338
-59
lines changed

6 files changed

+338
-59
lines changed

.github/workflows/Zapier.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Github --> Asana Add Comment Workflow
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: read
13+
steps:
14+
- name: Get Asana Task Corresponding to Issue
15+
env:
16+
ISSUE_ID: ${{ github.event.issue.id }}
17+
REPO_FULL_NAME: ${{ github.event.repository.full_name }}
18+
WORKSPACE_ID: "780103692902078"
19+
run: |
20+
REPO_SCOPED_ISSUE_ID="$REPO_FULL_NAME#$ISSUE_ID"
21+
22+
curl --request GET \
23+
--url "https://app.asana.com/api/1.0/workspaces/$WORKSPACE_ID/tasks/search?opt_fields=notes&text=$REPO_SCOPED_ISSUE_ID&sort_by=modified_at&sort_ascending=false" \
24+
--header 'accept: application/json' \
25+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
26+
--output response.json
27+
TASK_GID=$(jq -r '.data[0].gid' response.json)
28+
echo "TASK_GID=$TASK_GID" >> $GITHUB_ENV
29+
- name: Comment on Asana Task
30+
env:
31+
ISSUE_COMMENT: ${{ github.event.comment.body }}
32+
COMMENTER_NAME: ${{ github.event.comment.user.login }}
33+
run: |
34+
BODY_DATA=$(jq -n \
35+
--arg text "$ISSUE_COMMENT" \
36+
--arg commenter_name "$COMMENTER_NAME" \
37+
'{
38+
"data": {
39+
"text": "\($commenter_name) left a comment:\n\n\($text)",
40+
}
41+
}')
42+
curl --request POST \
43+
--url https://app.asana.com/api/1.0/tasks/$TASK_GID/stories \
44+
--header 'accept: application/json' \
45+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
46+
--header 'content-type: application/json' \
47+
--data "$BODY_DATA"
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Github --> Asana Create Task Workflow
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: read
13+
steps:
14+
- name: Create Asana task
15+
env:
16+
ISSUE_TITLE: ${{ github.event.issue.title }}
17+
ISSUE_BODY: ${{ github.event.issue.body }}
18+
ISSUE_HTML_URL: ${{ github.event.issue.html_url }}
19+
ISSUE_ID: ${{ github.event.issue.id }}
20+
ISSUE_NUMBER: ${{ github.event.issue.number }}
21+
REPO_FULL_NAME: ${{ github.event.repository.full_name }}
22+
SDK_PLATFORM_GROUP: "1208961704779581"
23+
SDK_PLATFORM_GROUP_SERVER: "1208961704779585"
24+
SDK_PLATFORM: "1208961704779592"
25+
SDK_PLATFORM_PYTHON: "1208961704779616"
26+
DSA_PRIORITY: "1208779519954980"
27+
DSA_PRIORITY_NO_PRIORITY: "1208779521616959"
28+
DSA_STATUS: "1210103546117753"
29+
DSA_STATUS_TRIAGE: "1210103546117756"
30+
DSA_REPO_TICKET_URL: "1210347857768758"
31+
WORKSPACE_ID: "780103692902078"
32+
PROJECT_ID_GITHUB_AND_IMPORTANT_SDK_ISSUES: "1208970714650308"
33+
PROJECT_ID_SDK_BACKLOG: "1208777198342772"
34+
run: |
35+
DATA_BODY=$(jq -n \
36+
--arg title "$ISSUE_TITLE" \
37+
--arg body "$ISSUE_BODY" \
38+
--arg url "$ISSUE_HTML_URL" \
39+
--arg id "$ISSUE_ID" \
40+
--arg number "$ISSUE_NUMBER" \
41+
--arg repo_full_name "$REPO_FULL_NAME" \
42+
--arg sdk_platform_group "$SDK_PLATFORM_GROUP" \
43+
--arg sdk_platform_group_server "$SDK_PLATFORM_GROUP_SERVER" \
44+
--arg sdk_platform "$SDK_PLATFORM" \
45+
--arg sdk_platform_python "$SDK_PLATFORM_PYTHON" \
46+
--arg dsa_priority "$DSA_PRIORITY" \
47+
--arg dsa_priority_no_priority "$DSA_PRIORITY_NO_PRIORITY" \
48+
--arg dsa_status "$DSA_STATUS" \
49+
--arg dsa_status_triage "$DSA_STATUS_TRIAGE" \
50+
--arg dsa_repo_ticket_url "$DSA_REPO_TICKET_URL" \
51+
--arg workspace_id "$WORKSPACE_ID" \
52+
--arg project_id_github_and_important_sdk_issues "$PROJECT_ID_GITHUB_AND_IMPORTANT_SDK_ISSUES" \
53+
--arg project_id_sdk_backlog "$PROJECT_ID_SDK_BACKLOG" \
54+
'{
55+
"data": {
56+
"custom_fields": {
57+
$sdk_platform_group: $sdk_platform_group_server,
58+
$sdk_platform: $sdk_platform_python,
59+
$dsa_priority: $dsa_priority_no_priority,
60+
$dsa_status: $dsa_status_triage,
61+
$dsa_repo_ticket_url: $url
62+
},
63+
"name": $title,
64+
"workspace": $workspace_id,
65+
"projects": [$project_id_github_and_important_sdk_issues, $project_id_sdk_backlog],
66+
"notes": "Issue ID: \($repo_full_name)#\($id)\nIssue number: \($number)\nCreated via GitHub Actions\n----\n\n\($body)"
67+
}
68+
}')
69+
70+
curl --request POST \
71+
--url https://app.asana.com/api/1.0/tasks?opt_pretty=true \
72+
--header 'accept: application/json' \
73+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
74+
--header 'content-type: application/json' \
75+
--data "$DATA_BODY" \
76+
--output response.json
77+
78+
TASK_GID=$(jq -r '.data.gid' response.json)
79+
echo "TASK_GID=$TASK_GID" >> $GITHUB_ENV
80+
- name: Move to "0 Unclassified" section in "Github & Important SDK Issues" project
81+
env:
82+
SECTION_ID_GITHUB_AND_IMPORTANT_SDK_ISSUES: "1208970755434051"
83+
run: |
84+
DATA_BODY=$(jq -n \
85+
--arg task_gid "$TASK_GID" \
86+
--arg section_id "$SECTION_ID_GITHUB_AND_IMPORTANT_SDK_ISSUES" \
87+
'{
88+
"data": {
89+
"task": $task_gid,
90+
"insert_after": "null"
91+
}
92+
}')
93+
94+
curl --request POST \
95+
--url https://app.asana.com/api/1.0/sections/$section_id/addTask \
96+
--header 'accept: application/json' \
97+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
98+
--header 'content-type: application/json' \
99+
--data "$DATA_BODY"
100+
- name: Move to "Untriaged" section in "SDK / Backlog" project
101+
env:
102+
SECTION_ID_SDK_BACKLOG: "1208899729378982"
103+
run: |
104+
DATA_BODY=$(jq -n \
105+
--arg task_gid "$TASK_GID" \
106+
--arg section_id "$SECTION_ID_SDK_BACKLOG" \
107+
'{
108+
"data": {
109+
"task": $task_gid,
110+
"insert_after": "null"
111+
}
112+
}')
113+
114+
curl --request POST \
115+
--url https://app.asana.com/api/1.0/sections/$section_id/addTask \
116+
--header 'accept: application/json' \
117+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
118+
--header 'content-type: application/json' \
119+
--data "$DATA_BODY"
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Github --> Asana Issue Updates Workflow
2+
3+
on:
4+
issues:
5+
types: [edited, deleted, closed, reopened, assigned, unassigned, labeled, unlabeled, milestoned, demilestoned, pinned, unpinned, locked, unlocked, transferred]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: read
13+
steps:
14+
- name: Get Asana Task Corresponding to Issue
15+
env:
16+
ISSUE_ID: ${{ github.event.issue.id }}
17+
REPO_FULL_NAME: ${{ github.event.repository.full_name }}
18+
WORKSPACE_ID: "780103692902078"
19+
run: |
20+
REPO_SCOPED_ISSUE_ID="$REPO_FULL_NAME#$ISSUE_ID"
21+
22+
curl --request GET \
23+
--url "https://app.asana.com/api/1.0/workspaces/$WORKSPACE_ID/tasks/search?opt_fields=notes&text=$REPO_SCOPED_ISSUE_ID&sort_by=modified_at&sort_ascending=false" \
24+
--header 'accept: application/json' \
25+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
26+
--output response.json
27+
TASK_GID=$(jq -r '.data[0].gid' response.json)
28+
echo "TASK_GID=$TASK_GID" >> $GITHUB_ENV
29+
- name: Determine Action and Post to Asana
30+
env:
31+
ACTION_TYPE: ${{ github.event.action }}
32+
ACTOR_NAME: ${{ github.event.sender.login }}
33+
ISSUE_TITLE: ${{ github.event.issue.title }}
34+
ISSUE_NUMBER: ${{ github.event.issue.number }}
35+
ISSUE_STATE: ${{ github.event.issue.state }}
36+
run: |
37+
# Map GitHub action types to human-readable descriptions
38+
case "$ACTION_TYPE" in
39+
"edited")
40+
ACTION_DESC="edited the issue"
41+
;;
42+
"deleted")
43+
ACTION_DESC="deleted the issue"
44+
;;
45+
"closed")
46+
ACTION_DESC="closed the issue"
47+
;;
48+
"reopened")
49+
ACTION_DESC="reopened the issue"
50+
;;
51+
"assigned")
52+
ACTION_DESC="assigned the issue"
53+
;;
54+
"unassigned")
55+
ACTION_DESC="unassigned the issue"
56+
;;
57+
"labeled")
58+
ACTION_DESC="added labels to the issue"
59+
;;
60+
"unlabeled")
61+
ACTION_DESC="removed labels from the issue"
62+
;;
63+
"milestoned")
64+
ACTION_DESC="added the issue to a milestone"
65+
;;
66+
"demilestoned")
67+
ACTION_DESC="removed the issue from a milestone"
68+
;;
69+
"pinned")
70+
ACTION_DESC="pinned the issue"
71+
;;
72+
"unpinned")
73+
ACTION_DESC="unpinned the issue"
74+
;;
75+
"locked")
76+
ACTION_DESC="locked the issue"
77+
;;
78+
"unlocked")
79+
ACTION_DESC="unlocked the issue"
80+
;;
81+
"transferred")
82+
ACTION_DESC="transferred the issue"
83+
;;
84+
*)
85+
ACTION_DESC="performed an action on the issue"
86+
;;
87+
esac
88+
89+
# Add additional context for specific actions based on webhook payload
90+
if [ "$ACTION_TYPE" = "assigned" ] && [ -n "${{ github.event.assignee.login }}" ]; then
91+
ACTION_DESC="assigned the issue to ${{ github.event.assignee.login }}"
92+
fi
93+
94+
if [ "$ACTION_TYPE" = "unassigned" ] && [ -n "${{ github.event.assignee.login }}" ]; then
95+
ACTION_DESC="unassigned the issue from ${{ github.event.assignee.login }}"
96+
fi
97+
98+
if [ "$ACTION_TYPE" = "labeled" ] && [ -n "${{ github.event.label.name }}" ]; then
99+
LABEL_COLOR="${{ github.event.label.color }}"
100+
ACTION_DESC="added label '${{ github.event.label.name }}' to the issue"
101+
if [ -n "$LABEL_COLOR" ]; then
102+
ACTION_DESC="$ACTION_DESC (color: #$LABEL_COLOR)"
103+
fi
104+
fi
105+
106+
if [ "$ACTION_TYPE" = "unlabeled" ] && [ -n "${{ github.event.label.name }}" ]; then
107+
LABEL_COLOR="${{ github.event.label.color }}"
108+
ACTION_DESC="removed label '${{ github.event.label.name }}' from the issue"
109+
if [ -n "$LABEL_COLOR" ]; then
110+
ACTION_DESC="$ACTION_DESC (color: #$LABEL_COLOR)"
111+
fi
112+
fi
113+
114+
if [ "$ACTION_TYPE" = "milestoned" ] && [ -n "${{ github.event.milestone.title }}" ]; then
115+
MILESTONE_DUE_DATE="${{ github.event.milestone.due_on }}"
116+
ACTION_DESC="added the issue to milestone '${{ github.event.milestone.title }}'"
117+
if [ -n "$MILESTONE_DUE_DATE" ] && [ "$MILESTONE_DUE_DATE" != "null" ]; then
118+
ACTION_DESC="$ACTION_DESC (due: $MILESTONE_DUE_DATE)"
119+
fi
120+
fi
121+
122+
if [ "$ACTION_TYPE" = "demilestoned" ] && [ -n "${{ github.event.milestone.title }}" ]; then
123+
ACTION_DESC="removed the issue from milestone '${{ github.event.milestone.title }}'"
124+
fi
125+
126+
if [ "$ACTION_TYPE" = "transferred" ] && [ -n "${{ github.event.changes.new_repository.full_name }}" ]; then
127+
ACTION_DESC="transferred the issue to repository ${{ github.event.changes.new_repository.full_name }}"
128+
fi
129+
130+
if [ "$ACTION_TYPE" = "edited" ] && [ -n "${{ github.event.changes.title.from }}" ]; then
131+
OLD_TITLE="${{ github.event.changes.title.from }}"
132+
NEW_TITLE="${{ github.event.issue.title }}"
133+
ACTION_DESC="edited the issue title from '$OLD_TITLE' to '$NEW_TITLE'"
134+
fi
135+
136+
echo "ACTION_DESC=$ACTION_DESC" >> $GITHUB_ENV
137+
138+
# Only proceed if we found a task
139+
if [ "$TASK_GID" != "null" ] && [ -n "$TASK_GID" ]; then
140+
# Create a more detailed message with additional context
141+
MESSAGE_TEXT="$ACTOR_NAME performed an action: $ACTION_DESC"
142+
143+
# Add issue state information for state changes
144+
if [ "$ACTION_TYPE" = "closed" ] || [ "$ACTION_TYPE" = "reopened" ]; then
145+
MESSAGE_TEXT=$(printf "%s\nIssue state: %s" "$MESSAGE_TEXT" "$ISSUE_STATE")
146+
fi
147+
148+
# Add repository information for transferred issues
149+
if [ "$ACTION_TYPE" = "transferred" ]; then
150+
REPO_NAME="${{ github.event.repository.full_name }}"
151+
MESSAGE_TEXT=$(printf "%s\nFrom repository: %s" "$MESSAGE_TEXT" "$REPO_NAME")
152+
fi
153+
154+
MESSAGE_TEXT=$(printf "%s\n\nIssue: #%s - %s" "$MESSAGE_TEXT" "$ISSUE_NUMBER" "$ISSUE_TITLE")
155+
156+
BODY_DATA=$(jq -n \
157+
--arg text "$MESSAGE_TEXT" \
158+
'{
159+
"data": {
160+
"text": $text
161+
}
162+
}')
163+
164+
curl --request POST \
165+
--url https://app.asana.com/api/1.0/tasks/$TASK_GID/stories \
166+
--header 'accept: application/json' \
167+
--header 'authorization: Bearer ${{ secrets.ASANA_PAT }}' \
168+
--header 'content-type: application/json' \
169+
--data "$BODY_DATA"
170+
else
171+
echo "No corresponding Asana task found for issue ID: $ISSUE_ID"
172+
fi

docs/GenericErrorErrorsInner.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)