Skip to content

Commit

Permalink
Merge pull request #8 from USRSE/add/github-link
Browse files Browse the repository at this point in the history
Adding github link and pull request script
  • Loading branch information
vsoch authored Feb 16, 2020
2 parents 73ba780 + 168d288 commit f566770
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mapbox: "pk.eyJ1IjoidnNvY2giLCJhIjoiY2sxdXE4dGZ6MGxveTNibzBqc2E5OXpzbiJ9.OdVyKYm

# Name of website
title: US-RSE Association
github_url: USRSE/usrse-map

# Short description of your site
description: US Research Software Engineer Association Map
Expand Down
1 change: 1 addition & 0 deletions _includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</li>
{% endif %}
{% endfor %}
<li><a href="https://github.com/{{ site.github_url }}" class="no-after" target="_blank"> github</i></a></li>
<li><a href="{{ site.url }}/search" class="no-after" id="search-toggle"> <i class="fa fa-search" style="margin-right:20px"></i></a></li>
</ul>
</div>
Expand Down
103 changes: 103 additions & 0 deletions scripts/pull-request.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash

# Suggested by Github actions to be strict
# Taken from https://www.github.com/vsoch/pull-request-action
set -e
set -o pipefail

################################################################################
# Global Variables (we can't use GITHUB_ prefix)
################################################################################

API_VERSION=v3
BASE=https://api.github.com
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
HEADER="Accept: application/vnd.github.${API_VERSION}+json"
HEADER="${HEADER}; application/vnd.github.antiope-preview+json; application/vnd.github.shadow-cat-preview+json"

# URLs
REPO_URL="${BASE}/repos/${GITHUB_REPOSITORY}"
PULLS_URL=$REPO_URL/pulls

################################################################################
# Helper Functions
################################################################################


check_credentials() {

if [[ -z "${GITHUB_TOKEN}" ]]; then
echo "You must include the GITHUB_TOKEN as an environment variable."
exit 1
fi

}

check_events_json() {

if [[ ! -f "${GITHUB_EVENT_PATH}" ]]; then
echo "Cannot find Github events file at ${GITHUB_EVENT_PATH}";
exit 1;
fi
echo "Found ${GITHUB_EVENT_PATH}";

}

create_pull_request() {

SOURCE="${1}" # from this branch
TARGET="${2}" # pull request TO this target

# Check if the branch already has a pull request open
TITLE='Updating Membership Map'
BODY="This is a pull request to update the US-RSE map. ${BODY}"
DATA="{\"base\":\"${TARGET}\", \"head\":\"${SOURCE}\", \"body\":\"${BODY}\"}"
RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X GET --data "${DATA}" ${PULLS_URL})
PR=$(echo "${RESPONSE}" | jq --raw-output '.[] | .head.ref')
echo "Response ref: ${PR}"

# Option 1: The pull request is already open
if [[ "${PR}" == "${SOURCE}" ]]; then
echo "Pull request from ${SOURCE} to ${TARGET} is already open!"

# Option 2: Open a new pull request
else
# Post the pull request
DATA="{\"title\":\"${TITLE}\", \"base\":\"${TARGET}\", \"head\":\"${SOURCE}\", \"body\":\"${BODY}\"}"
echo "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}"
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}
echo $?
fi
}


main () {

# path to file that contains the POST response of the event
# Example: https://github.com/actions/bin/tree/master/debug
# Value: /github/workflow/event.json
check_events_json;

# User specified branch for PR
if [ -z "${BRANCH_FROM}" ]; then
echo "You must specify a branch to PR from."
exit 1
fi
echo "Branch for pull request is $BRANCH_FROM"

if [ -z "${BRANCH_AGAINST}" ]; then
BRANCH_AGAINST=master
fi
echo "Pull request will go against ${BRANCH_AGAINST}"

# Ensure we have a GitHub token
check_credentials
create_pull_request "${BRANCH_FROM}" "${BRANCH_AGAINST}"

}

echo "==========================================================================
START: Creating Membership Map Update Pull Request!";
main;
echo "==========================================================================
END: Finished";

0 comments on commit f566770

Please sign in to comment.