|
| 1 | +name: 'Assign Android Release Task in Asana' |
| 2 | +description: 'Assigns the latest Asana Release task to the user who runs the workflow' |
| 3 | +inputs: |
| 4 | + task_name: |
| 5 | + description: 'The name of the task to search for' |
| 6 | + required: true |
| 7 | + asana_token: |
| 8 | + description: 'Asana Personal Access Token' |
| 9 | + required: true |
| 10 | + project_gid: |
| 11 | + description: 'Asana Project GID to search within' |
| 12 | + required: true |
| 13 | + username: |
| 14 | + description: 'The Github username to search for' |
| 15 | + required: true |
| 16 | +runs: |
| 17 | + using: 'composite' |
| 18 | + steps: |
| 19 | + - name: Find task in Asana and assign it to owner |
| 20 | + shell: bash |
| 21 | + run: | |
| 22 | + task_name="${{ inputs.task_name }}" |
| 23 | + asana_token="${{ inputs.asana_token }}" |
| 24 | + project_gid="${{ inputs.project_gid }}" |
| 25 | + username="${{ inputs.username }}" |
| 26 | +
|
| 27 | + # Make the API request to get tasks from the specified project |
| 28 | + response=$(curl -s -X GET "https://app.asana.com/api/1.0/projects/${project_gid}/tasks" \ |
| 29 | + -H "Authorization: Bearer ${asana_token}") |
| 30 | +
|
| 31 | + # Check if the response contains any tasks that match the specified task name exactly |
| 32 | + task_id=$(echo "$response" | jq -r '.data[] | select(.name == "'"$task_name"'") | .gid') |
| 33 | +
|
| 34 | + if [ -z "$task_id" ]; then |
| 35 | + echo "No tasks with the exact name '$task_name' found in project GID '$project_gid'." |
| 36 | + exit 1 |
| 37 | + else |
| 38 | + echo "Task ID for the task named '$task_name': $task_id" |
| 39 | + fi |
| 40 | + |
| 41 | + asana_user_id=$(grep -E "^$username: " .github/actions/assign-release-task/github_asana_mapping.yml | awk -F': ' '{print $2}' | tr -d '"') |
| 42 | +
|
| 43 | + if [ -z "asana_user_id" ]; then |
| 44 | + echo "User $username not found." |
| 45 | + exit 1 |
| 46 | + else |
| 47 | + echo "User ID for $username: $asana_user_id" |
| 48 | + fi |
| 49 | + |
| 50 | + echo "Assigning task ID $task_id to user ID $asana_user_id" |
| 51 | +
|
| 52 | + # Assign the task to the user |
| 53 | + response=$(curl -s -X PUT "https://app.asana.com/api/1.0/tasks/${task_id}" \ |
| 54 | + -H "Authorization: Bearer ${asana_token}" \ |
| 55 | + -H "Content-Type: application/json" \ |
| 56 | + -d "{\"data\": {\"assignee\": \"${asana_user_id}\"}}") |
| 57 | +
|
| 58 | + # Check if the assignment was successful |
| 59 | + status=$(echo $response | jq -r '.errors') |
| 60 | +
|
| 61 | + if [ "$status" == "null" ]; then |
| 62 | + echo "Task $task_id successfully assigned to user $asana_user_id." |
| 63 | + else |
| 64 | + echo "Failed to assign task: $status" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + |
0 commit comments