-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get more PR info and do better Slack messaging (#5)
* Add get-pr-info command * testing * iterating * iterating * iterating * iterate * iterate * iterate * iterate * iterate * iterate * iterate * foo * bar * baz * baz * baz * baz * baz * baz * baz * i should go to sleep * ... * ... * ... * ... * ... * ... * ... * ... * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * gkwb * update description and stuff * foo * foo * foo * foo * foo * Fixing bugs * clean up and documentation * prettify
- Loading branch information
1 parent
521a8b7
commit d7d1feb
Showing
8 changed files
with
279 additions
and
89 deletions.
There are no files selected for viewing
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
description: | | ||
Gets and sets the following environment variables: | ||
* `GITHUB_PR_BASE_BRANCH` - The base branch for the PR. | ||
* `GITHUB_PR_NUMBER` - The number of the PR. | ||
* `GITHUB_PR_TITLE` - The title of the PR. | ||
* `GITHUB_PR_COMMIT_MESSAGE` - The current commit's message. (Optional) | ||
* `GITHUB_PR_AUTHOR_USERNAME` - The PR author's username. | ||
* `GITHUB_PR_AUTHOR_NAME` - The PR author's name. (Optional) | ||
* `GITHUB_PR_AUTHOR_EMAIL` - The PR author's email address. (Optional) | ||
Requires `GITHUB_EMAIL` and `GITHUB_PASSWORD` to be set as environment variables. | ||
parameters: | ||
get_pr_author_email: | ||
description: | | ||
If true, also sets GITHUB_PR_AUTHOR_EMAIL. This requires an additional API call. | ||
type: boolean | ||
default: false | ||
get_pr_author_name: | ||
description: | | ||
If true, also sets GITHUB_PR_AUTHOR_NAME. This requires an additional API call. | ||
type: boolean | ||
default: false | ||
get_commit_message: | ||
description: | | ||
If true, also sets GITHUB_PR_COMMIT_MESSAGE. This requires an additional API call. | ||
type: boolean | ||
default: false | ||
steps: | ||
- run: | ||
when: always | ||
name: Get PR information | ||
command: | | ||
# Check `jq` dependency | ||
if ! (command -v jq >/dev/null 2>&1); then | ||
echo "This command requires jq to be installed" | ||
exit 1 | ||
fi | ||
PR_NUMBER=$(echo "$CIRCLE_PULL_REQUEST" | sed "s/.*\/pull\///") | ||
echo "PR_NUMBER: $PR_NUMBER" | ||
echo "export GITHUB_PR_NUMBER=$PR_NUMBER" >> $BASH_ENV | ||
API_GITHUB="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" | ||
PR_REQUEST_URL="$API_GITHUB/pulls/$PR_NUMBER" | ||
PR_RESPONSE=$(curl --user "${GITHUB_USERNAME}:${GITHUB_PASSWORD}" "$PR_REQUEST_URL") | ||
PR_TITLE=$(echo $PR_RESPONSE | jq -e '.title' | tr -d '"') | ||
echo "PR_TITLE: $PR_TITLE" | ||
echo "export GITHUB_PR_TITLE='$PR_TITLE'" >> $BASH_ENV | ||
PR_BASE_BRANCH=$(echo $PR_RESPONSE | jq -e '.base.ref' | tr -d '"') | ||
echo "PR_BASE_BRANCH: $PR_BASE_BRANCH" | ||
echo "export GITHUB_PR_BASE_BRANCH='$PR_BASE_BRANCH'" >> $BASH_ENV | ||
PR_AUTHOR_USERNAME=$(echo $PR_RESPONSE | jq -e '.user.login' | tr -d '"') | ||
echo "PR_AUTHOR_USERNAME: $PR_AUTHOR_USERNAME" | ||
echo "export GITHUB_PR_AUTHOR_USERNAME='$PR_AUTHOR_USERNAME'" >> $BASH_ENV | ||
if [[ << parameters.get_pr_author_email >> == true || << parameters.get_pr_author_name >> ]]; then | ||
# We need to use the email address associated with the merge_commit_sha since | ||
# CIRCLE_SHA1 may have been authored by someone who is not the PR author. | ||
# Sadly, PR_RESPONSE doesn't include the email associated with the merge_commit_sha. | ||
# So we have to get that from the commit information. | ||
PR_MERGE_COMMIT_SHA=$(echo $PR_RESPONSE | jq -e '.merge_commit_sha' | tr -d '"') | ||
COMMIT_REQUEST_URL="$API_GITHUB/commits/$PR_MERGE_COMMIT_SHA" | ||
COMMIT_RESPONSE=$(curl --user "${GITHUB_USERNAME}:${GITHUB_PASSWORD}" "$COMMIT_REQUEST_URL") | ||
fi | ||
<<# parameters.get_pr_author_email >> | ||
PR_AUTHOR_EMAIL=$(echo $COMMIT_RESPONSE | jq -e '.commit.author.email' | tr -d '"') | ||
echo "PR_AUTHOR_EMAIL: $PR_AUTHOR_EMAIL" | ||
echo "export GITHUB_PR_AUTHOR_EMAIL='$PR_AUTHOR_EMAIL'" >> $BASH_ENV | ||
<</ parameters.get_pr_author_email >> | ||
<<# parameters.get_pr_author_name >> | ||
PR_AUTHOR_NAME=$(echo $COMMIT_RESPONSE | jq -e '.commit.author.name' | tr -d '"') | ||
echo "PR_AUTHOR_NAME: $PR_AUTHOR_NAME" | ||
echo "export GITHUB_PR_AUTHOR_NAME='$PR_AUTHOR_NAME'" >> $BASH_ENV | ||
<</ parameters.get_pr_author_name >> | ||
<<# parameters.get_commit_message >> | ||
COMMIT_REQUEST_URL="$API_GITHUB/commits/$CIRCLE_SHA1" | ||
COMMIT_RESPONSE=$(curl --user "${GITHUB_USERNAME}:${GITHUB_PASSWORD}" "$COMMIT_REQUEST_URL") | ||
PR_COMMIT_MESSAGE=$(echo $COMMIT_RESPONSE | jq -e '.commit.message' | tr -d '"') | ||
echo "PR_COMMIT_MESSAGE: $PR_COMMIT_MESSAGE" | ||
echo "export GITHUB_PR_COMMIT_MESSAGE='$PR_COMMIT_MESSAGE'" >> $BASH_ENV | ||
<</ parameters.get_commit_message >> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.