Bulk Issues Creation #170
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bulk Issues Creation | |
on: | |
workflow_dispatch: | |
inputs: | |
organization: | |
description: "Github organization for the listed repos" | |
type: choice | |
required: true | |
default: farhan-test-org | |
options: | |
- openedx | |
- edx | |
- farhan-test-org | |
repos_list: | |
description: "List of repositories in the format 'x', 'y', 'z'..." | |
type: string | |
required: true | |
issue_labels: | |
description: "List of labels in the format 'x', 'y', 'z'..." | |
type: string | |
required: false | |
jobs: | |
prepare_repos_list: | |
runs-on: ubuntu-20.04 | |
outputs: | |
repos_list: ${{ steps.repos_list.outputs.list }} | |
steps: | |
- name: Get repos list | |
id: repos_list | |
run: | | |
echo "list=[${{github.event.inputs.repos_list}}]" >> $GITHUB_OUTPUT | |
create_issue_list_files: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Create issue list files | |
run: | | |
# Add headers in the files | |
echo "Organization, Repository, Issue Url" > issue_list.csv | |
echo "---------------------------------------------------------------------" > issue_list.txt | |
echo "List of issues created in the relevant repos." >> issue_list.txt | |
echo "Output is in the tasks list format to directly copy them in git epic " >> issue_list.txt | |
echo "---------------------------------------------------------------------" >> issue_list.txt | |
echo "\`\`\`[tasklist]" >> issue_list.txt | |
echo "### Tasks" >> issue_list.txt | |
shell: bash | |
- name: Upload issue list files as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: issues-artifact | |
path: issue_list.* | |
bulk_issue_creation: | |
runs-on: ubuntu-20.04 | |
needs: [ prepare_repos_list, create_issue_list_files ] | |
strategy: | |
fail-fast: false | |
max-parallel: 1 | |
matrix: | |
repo: ${{fromJson(needs.prepare_repos_list.outputs.repos_list)}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Read issue details from issue.json | |
id: issue_details | |
run: | | |
issue_json=$(cat issue.json) | |
issue_title=$(echo "$issue_json" | jq -r '.title') | |
issue_body=$(echo "$issue_json" | jq -r '.body') | |
echo "issue_title=$issue_title" >> $GITHUB_ENV | |
echo "issue_body=$issue_body" >> $GITHUB_ENV | |
- name: Download issues-artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: issues-artifact | |
- name: Create Issue in ${{ matrix.repo }} | |
run: | | |
labels_string=["${{ github.event.inputs.issue_labels }}"] | |
labels_array=$(echo "$labels_string" | sed "s/'/\"/g" | jq -c .) | |
data=$(jq -n \ | |
--arg title "$issue_title" \ | |
--arg body "$issue_body" \ | |
--argjson labels "$labels_array" \ | |
'{ title: $title, body: $body, labels: $labels }') | |
echo "data: $data" | |
# Curl API call to create the issue | |
response=$(curl -s -X POST \ | |
-H "Authorization: token ${{ secrets.REQUIREMENTS_BOT_GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github+json" \ | |
https://api.github.com/repos/${{ github.event.inputs.organization }}/${{ matrix.repo }}/issues \ | |
-d "$data") | |
echo "Issue creation API response:" | |
echo "$response" | jq . # Pretty print the response | |
# Check if response contains html_url | |
issue_url=$(echo "$response" | jq -r '.html_url') | |
if [ "$issue_url" == "null" ]; then | |
echo "Error: 'html_url' field not found in response" | |
exit 1 | |
fi | |
echo "Issue url: $issue_url" | |
# Append the issue to the issue list files | |
echo "${{ github.event.inputs.organization }}, ${{ matrix.repo }}, $issue_url" >> issue_list.csv | |
echo "- [ ] ${{ matrix.repo }} $issue_url" >> issue_list.txt | |
- name: Upload updated issue list files | |
uses: actions/upload-artifact@v3 | |
with: | |
name: issues-artifact | |
path: issue_list.* | |
finalize_issues_list: | |
runs-on: ubuntu-20.04 | |
needs: [ bulk_issue_creation ] | |
steps: | |
- name: Download issues-artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: issues-artifact | |
- name: Print list of created issues on console | |
run: | | |
# Add ending tag in the file | |
echo '```' >> issue_list.txt | |
cat issue_list.csv | |
shell: bash | |
- name: Upload final issues list file | |
uses: actions/upload-artifact@v3 | |
with: | |
name: issues-artifact | |
path: issue_list.* | |
- name: How to download Artifact (Issues list files) | |
run: | | |
echo "To download the artifact find 'Artifacts' secion on the summary page of the run:" | |
echo "Summary page: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |