Skip to content

Instantly share code, notes, and snippets.

@rajivreddy
Forked from StevenACoffman/github.sh
Created May 4, 2021 02:31
Show Gist options
  • Save rajivreddy/7a850cb6de9a9d62bd73bb336d39b4ca to your computer and use it in GitHub Desktop.
Save rajivreddy/7a850cb6de9a9d62bd73bb336d39b4ca to your computer and use it in GitHub Desktop.

Revisions

  1. @StevenACoffman StevenACoffman revised this gist Sep 30, 2016. 1 changed file with 21 additions and 2 deletions.
    23 changes: 21 additions & 2 deletions github.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,26 @@
    #!/bin/bash

    # Run these functions like this:
    # BUILD_URL="http://www.google.com";gh_post_success_comment "mylists-service" "48"
    #Jenkins provides:
    #GIT_COMMIT like ce9a3c1404e8c91be604088670e93434c4253f03
    #GIT_BRANCH like origin/master
    #BUILD_URL like http://jenkins.test.cirrostratus.org/job/Article_View_c20n_Full_Non_Destructive_Full_Suite/1334/

    # per https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
    # The jenkins pull request builder plugin (if configured) will provide these:
    #ghprbPullId
    #ghprbActualCommit
    #ghprbActualCommitAuthor
    #ghprbActualCommitAuthorEmail
    #ghprbPullDescription
    #ghprbPullId
    #ghprbPullLink
    #ghprbPullTitle
    #ghprbSourceBranch
    #ghprbTargetBranch
    #sha1

    #Run these functions like this:
    # BUILD_URL="";gh_post_success_comment "mylists-service" "48"

    function gh_post_success_comment() {
    #Expects that the GITHUB_AUTH_TOKEN is provided already in the environment
  2. @StevenACoffman StevenACoffman revised this gist Sep 30, 2016. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions github.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    #!/bin/bash

    #!/bin/bash

    #Run these functions like this:
    # Run these functions like this:
    # BUILD_URL="http://www.google.com";gh_post_success_comment "mylists-service" "48"

    function gh_post_success_comment() {
  3. @StevenACoffman StevenACoffman created this gist Sep 30, 2016.
    40 changes: 40 additions & 0 deletions github.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/bin/bash

    #!/bin/bash

    #Run these functions like this:
    # BUILD_URL="http://www.google.com";gh_post_success_comment "mylists-service" "48"

    function gh_post_success_comment() {
    #Expects that the GITHUB_AUTH_TOKEN is provided already in the environment
    #Expects that BUILD_URL is provided already in the environment
    # 1st required argument is the repository name like "jstor" or "mylists-service"
    # 2nd required argument is the pull request number
    # 3rd optional argument is the message itself
    REPO="${1:-please-specify-repo}"
    PULL_REQUEST_NUMBER="${2:-please-specify-pr-number}"
    COMMENT_DEFAULT=":white_check_mark: [All Checks Passed](${BUILD_URL})"
    COMMENT_MARKDOWN="${3:-$COMMENT_DEFAULT}"
    curl -v -H "Content-Type: application/json" \
    -H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
    -X POST \
    -d "{\"body\":\"${COMMENT_MARKDOWN}\"}" \
    "https://api.github.com/repos/ithaka/${REPO}/issues/${PULL_REQUEST_NUMBER}/comments"
    }

    function gh_post_failure_comment() {
    #Expects that the GITHUB_AUTH_TOKEN is provided already in the environment
    #Expects that BUILD_URL is provided already in the environment
    # 1st required argument is the repository name like "jstor" or "mylists-service"
    # 2nd required argument is the pull request number
    # 3rd optional argument is the message itself
    REPO="${1:-please-specify-repo}"
    PULL_REQUEST_NUMBER="${2:-please-specify-pr-number}"
    COMMENT_DEFAULT=":x: [Failure](${BUILD_URL})"
    COMMENT_MARKDOWN="${3:-$COMMENT_DEFAULT}"
    curl -v -H "Content-Type: application/json" \
    -H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
    -X POST \
    -d "{\"body\":\"${COMMENT_MARKDOWN}\"}" \
    "https://api.github.com/repos/ithaka/${REPO}/issues/${PULL_REQUEST_NUMBER}/comments"
    }