|
1 | 1 | #!/bin/bash
|
2 |
| - |
3 | 2 | # Writes a change log to stdout using the GitHub API and the milestone associated with the specified Git tag
|
4 |
| -function changelog() { |
5 | 3 |
|
6 |
| - # Give function arguments meaningful names |
7 |
| - GIT_TAG="$1" |
8 |
| - GITHUB_API_URL="$2" |
| 4 | +# Write Markdown headers for the Git tag and release date |
| 5 | +echo "##${TRAVIS_TAG}" |
| 6 | +echo "######Released on $(date '+%Y-%m-%d')" |
9 | 7 |
|
10 |
| - # Write Markdown headers for the Git tag and release date |
11 |
| - echo "##${GIT_TAG}" |
12 |
| - echo "######Released on $(date '+%Y-%m-%d')" |
| 8 | +# Query GitHub API for a milestone matching the Git tag |
| 9 | +GITHUB_API_URL="https://api.github.com/repos/${TRAVIS_REPO_SLUG}" |
| 10 | +MILESTONE_ARRAY=( \ |
| 11 | + $(curl --silent "${GITHUB_API_URL}/milestones?state=all" \ |
| 12 | + | jq --arg title "${TRAVIS_TAG}" '.[] | select(.title == $title) | .number') \ |
| 13 | + ) > /dev/null |
13 | 14 |
|
14 |
| - # Query GitHub API for a milestone matching the Git tag |
15 |
| - MILESTONE_ARRAY=( \ |
16 |
| - $(curl --silent "${GITHUB_API_URL}/milestones?state=all" \ |
17 |
| - | jq --arg title "${GIT_TAG}" '.[] | select(.title == $title) | .number') \ |
| 15 | +# When GitHub has a milestone matching the Git tag, write milestone related information to the change log |
| 16 | +if [[ "${#MILESTONE_ARRAY[@]}" -ne 0 ]]; then |
| 17 | + # Write the milestone description to the change log |
| 18 | + MILESTONE_DESCRIPTION=( \ |
| 19 | + $(curl --silent "${GITHUB_API_URL}/milestones/${MILESTONE_ARRAY[0]}" \ |
| 20 | + | jq .description) \ |
18 | 21 | ) > /dev/null
|
| 22 | + MILESTONE_DESCRIPTION=${MILESTONE_DESCRIPTION[*]#\"} |
| 23 | + echo ${MILESTONE_DESCRIPTION[*]%\"} |
19 | 24 |
|
20 |
| - # When GitHub has a milestone matching the Git tag, write milestone related information to the change log |
21 |
| - if [[ "${#MILESTONE_ARRAY[@]}" -ne 0 ]]; then |
22 |
| - # Write the milestone description to the change log |
23 |
| - MILESTONE_DESCRIPTION=( \ |
24 |
| - $(curl --silent "${GITHUB_API_URL}/milestones/${MILESTONE_ARRAY[0]}" \ |
25 |
| - | jq .description) \ |
26 |
| - ) > /dev/null |
27 |
| - MILESTONE_DESCRIPTION=${MILESTONE_DESCRIPTION[*]#\"} |
28 |
| - echo ${MILESTONE_DESCRIPTION[*]%\"} |
29 |
| - |
30 |
| - # Write the milestone's associated issues to the change log with each issue on a separate line with the issue |
31 |
| - # title, issue number, and a link to the issue on GitHub.com, all in markdown format: .title ([#.number](.html_url)) |
32 |
| - ISSUE_ARRAY=$(curl --silent "${GITHUB_API_URL}/issues?state=all&milestone=${MILESTONE_ARRAY[0]}" | jq -c '.[] | [.title, .number, .html_url]') >> /dev/null |
33 |
| - while read line |
34 |
| - do |
35 |
| - echo ${line} | sed 's#\["\(.*\)",\(.*\),"\(.*\)"\]#- \1 ([\#\2](\3))#' |
36 |
| - done <<< "${ISSUE_ARRAY[*]}" |
37 |
| - fi |
38 |
| -} |
| 25 | + # Write the milestone's associated issues to the change log with each issue on a separate line with the issue |
| 26 | + # title, issue number, and a link to the issue on GitHub.com, all in markdown format: .title ([#.number](.html_url)) |
| 27 | + ISSUE_ARRAY=$(curl --silent "${GITHUB_API_URL}/issues?state=all&milestone=${MILESTONE_ARRAY[0]}" | jq -c '.[] | [.title, .number, .html_url]') >> /dev/null |
| 28 | + while read line |
| 29 | + do |
| 30 | + echo ${line} | sed 's#\["\(.*\)",\(.*\),"\(.*\)"\]#- \1 ([\#\2](\3))#' |
| 31 | + done <<< "${ISSUE_ARRAY[*]}" |
| 32 | +fi |
0 commit comments