From bde68436a8cdf31c878ff6169be52f0cbb00d53a Mon Sep 17 00:00:00 2001 From: ading007 Date: Wed, 16 Jun 2021 10:57:33 +0800 Subject: [PATCH] Fixed to access github api error (#708) --- .drone.yml | 3 +-- tests/check-org-membership.sh | 26 ++++++++++++++++++++++++++ tests/pass-rate.sh | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100755 tests/check-org-membership.sh diff --git a/.drone.yml b/.drone.yml index 5acc65593..c2351dfdf 100644 --- a/.drone.yml +++ b/.drone.yml @@ -20,8 +20,7 @@ pipeline: secrets: - github_automation_api_key commands: - - echo ${DRONE_COMMIT_AUTHOR} - - /bin/bash -c '[[ ! $(curl --silent "https://api.github.com/orgs/vmware/members/${DRONE_COMMIT_AUTHOR}?access_token=$GITHUB_AUTOMATION_API_KEY") ]]' + - tests/check-org-membership.sh when: status: success diff --git a/tests/check-org-membership.sh b/tests/check-org-membership.sh new file mode 100755 index 000000000..1a4471384 --- /dev/null +++ b/tests/check-org-membership.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Copyright 2020-2021 VMware, Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -ex + +echo ${DRONE_COMMIT_AUTHOR} + +if [ ! $(curl --silent -H "Authorization: token $GITHUB_AUTOMATION_API_KEY" "https://api.github.com/orgs/vmware/members/${DRONE_COMMIT_AUTHOR}") ]; then + echo "checked origin membership successfully" +else + echo "failed to check origin membership" + exit 1 +fi diff --git a/tests/pass-rate.sh b/tests/pass-rate.sh index 71b425c7a..cef3235a6 100755 --- a/tests/pass-rate.sh +++ b/tests/pass-rate.sh @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -curl -s https://api.github.com/repos/vmware/vic-ui/commits?access_token=$GITHUB_AUTOMATION_API_KEY | jq -r ".[].sha" | xargs -n1 -I{} curl -s https://api.github.com/repos/vmware/vic-ui/statuses/{}?access_token=$GITHUB_AUTOMATION_API_KEY | jq -r ".[-0].state" > status.out +curl -s -H "Authorization: token $GITHUB_AUTOMATION_API_KEY" https://api.github.com/repos/vmware/vic-ui/commits | jq -r ".[].sha" | xargs -n1 -I{} curl -s -H "Authorization: token $GITHUB_AUTOMATION_API_KEY" https://api.github.com/repos/vmware/vic-ui/statuses/{} | jq -r ".[-0].state" > status.out failures=$(cat status.out | grep -c failure) echo "Number of failed merges to master in the last 30 merges: $failures"