-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue #684 This commit is to add an API to do a review result on a pull request with curl The API consists of five arguments as folows. * arg1: Token number * arg2: Event (e.g., APPROVE, REQUEST_CHANGES, or COMMENT) * arg3: Description * arg4: Commit ID * arg5: API address Note that you can use this API such as the below statement. ```bash message="All CI checkers are successfully passed. LGTM." cibot_review $TOKEN "APPROVE" "$message" "$input_commit" "$GITHUB_WEBHOOK_API/$GITHUB_ACCOUNT/${PRJ_REPO_UPSTREAM_SERVER}/pulls/$input_pr/reviews ``` Signed-off-by: Geunsik Lim <[email protected]>
- Loading branch information
Geunsik Lim
authored and
Dongju Chae
committed
Dec 17, 2020
1 parent
bf9f2d8
commit 8cb6be3
Showing
1 changed file
with
70 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,15 @@ | |
|
||
|
||
## | ||
# @file api_collection.sh | ||
# @brief API collection to send webhook messages to a github server and to manage comment functions | ||
|
||
# @file api_collection.sh | ||
# @author Geunsik Lim <[email protected]> | ||
# @brief API collection to send webhook messages to a github server and to manage comment functions | ||
# @note API list is as follows. | ||
# cibot_comment() | ||
# cibot_report() | ||
# cibot_review() | ||
# goto_repodir() | ||
# check_dep_cmd() | ||
|
||
## | ||
# @brief API to write comment to new pull request with curl | ||
|
@@ -48,8 +54,8 @@ function cibot_comment(){ | |
# @see https://developer.github.com/v3/repos/deployments/ | ||
TRIM_MESSAGE="$MESSAGE" | ||
|
||
# let's do PR report | ||
/usr/bin/curl -H "Content-Type: application/json" \ | ||
# let's do a comment to a PR | ||
/usr/bin/curl -H "Content-Type: application/json" \ | ||
-H "Authorization: token "$TOKEN" " \ | ||
--data "{\"body\":\"$TRIM_MESSAGE\"}" \ | ||
$COMMIT_ADDRESS | ||
|
@@ -104,7 +110,7 @@ function cibot_report(){ | |
fi | ||
echo -e "[DEBUG] The edited TRIM_DESCRIPTION is \"$TRIM_DESCRIPTION\"." | ||
|
||
# let's send PR report to change PR status | ||
# let's send examination results to change PR status | ||
/usr/bin/curl -H "Content-Type: application/json" \ | ||
-H "Authorization: token "$TOKEN" " \ | ||
--data "{\"state\":\"$STATE\",\"context\":\"$CONTEXT\",\"description\":\"$TRIM_DESCRIPTION\",\"target_url\":\"$TARGET_URL\"}" \ | ||
|
@@ -118,6 +124,64 @@ function cibot_report(){ | |
echo -e "[DEBUG] -----------------------------------------------------------------------------" | ||
} | ||
|
||
## | ||
# @brief API to do a review result on a pull request with curl | ||
# @param | ||
# arg1: token number | ||
# arg2: event (e.g., APPROVE, REQUEST_CHANGES, or COMMENT) | ||
# arg3: description | ||
# arg4: commit ID | ||
# arg5: API address | ||
# @note The below statement shows how to use this API. | ||
# message="All CI checkers are successfully passed. LGTM." | ||
# | ||
# cibot_review $TOKEN "APPROVE" "$message" "$input_commit" | ||
# "$GITHUB_WEBHOOK_API/$GITHUB_ACCOUNT/${PRJ_REPO_UPSTREAM_SERVER}/pulls/$input_pr/reviews" | ||
# | ||
function cibot_review(){ | ||
# check if input argument is correct. | ||
if [[ $1 == "" || $2 == "" || $3 == "" || $4 == "" || $5 == "" ]]; then | ||
printf "[DEBUG] ERROR: Please, input correct arguments to run cibot_report function.\n" | ||
exit 1 | ||
fi | ||
# argeuments | ||
TOKEN="$1" | ||
EVENT="$2" | ||
DESCRIPTION="$3" | ||
COMMIT_ID="$4" | ||
API_ADDRESS="$5" | ||
|
||
echo -e "[DEBUG] Running the curl-based $FUNCNAME API to change the PR status." | ||
echo -e "[DEBUG] EVENT: $EVENT" | ||
|
||
# trim the message that exceeds 140 characters in case of PR status change. | ||
# In case that cibot create deployment statuses for a given PR: | ||
# A short description of the status. Maximum length of 140 characters. Default: "" | ||
# @see https://developer.github.com/v3/repos/deployments/ | ||
TRIM_DESCRIPTION="" | ||
msg_max=120 | ||
num_chars=`echo $DESCRIPTION | wc -c` | ||
echo -e "[DEBUG] The length of a webhook message is \"$num_chars\"." | ||
echo -e "[DEBUG] The original DESCRIPTION is \"$DESCRIPTION\"." | ||
if [[ $num_chars -gt $msg_max ]]; then | ||
TRIM_DESCRIPTION="`echo $DESCRIPTION | cut -c 1-${msg_max}` ..." | ||
else | ||
TRIM_DESCRIPTION="$DESCRIPTION" | ||
fi | ||
echo -e "[DEBUG] The edited TRIM_DESCRIPTION is \"$TRIM_DESCRIPTION\"." | ||
|
||
# let's send a review result on a PR | ||
# https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#create-a-review-for-a-pull-request | ||
/usr/bin/curl -X POST -H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token "$TOKEN" " \ | ||
--data "{\"commitid\":\"$COMMIT_ID\",\"event\":\"$EVENT\",\"body\":\"$TRIM_DESCRIPTION\"}" \ | ||
$API_ADDRESS | ||
|
||
echo -e "[DEBUG] -----------------------------------------------------------------------------" | ||
echo -e "[DEBUG] $TRIM_DESCRIPTION" | ||
echo -e "[DEBUG] -----------------------------------------------------------------------------" | ||
} | ||
|
||
## | ||
# @brief API to move to a git repository folder that imported a specified branch name | ||
# @param | ||
|