Skip to content

Commit cd940d8

Browse files
committed
chore: add github-to-asana workflows
1 parent 4ed1a47 commit cd940d8

File tree

3 files changed

+330
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)