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