Skip to content

Commit

Permalink
rm -e (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesleonard authored Oct 17, 2023
1 parent 7f00f90 commit 71037af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ in [karthikraina32/concourse-trigger-guard](https://github.com/karthikraina32/co
* `organization`: *Required.* The name of the organization to authorize users and/or teams under.
* `teams`: *Optional.* A list of teams to authorize within the given organization. Required if `users` is not specified.
* `users`: *Optional.* The name of the user to authorize. Required if `teams` is not specified.
* `access_token`: *Required.* A GitHub token with `read:org` scope.
* `access_token`: *Required.* A GitHub token with `read:org` scope if using GHEC. Use `admin:org` scope if using with GHES.
* `ghe_host`: *Optional.* The hostname of the GitHub Enterprise instance to communicate with the GitHub API.
* `suffix`: *Optional.* A suffix to append to the `$BUILD_CREATED_BY` metadata environment variable. This is useful when
using GitHub Enterprise Cloud and your company appends a suffix to the username.
Expand Down
28 changes: 13 additions & 15 deletions assets/out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e -u
set -u

export GH_DEBUG=0

Expand Down Expand Up @@ -60,13 +60,12 @@ log_error() {
# Returns 302 if requester is not an org members
# Returns 404 if requester and user is not a member
declare -F check_org_membership >/dev/null || check_org_membership() {
set +e
response_with_headers=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/orgs/$org/members/$username" \
-i)
set -e
response_with_headers=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/orgs/$org/members/$username" \
-i)

response_status_code=$(echo "$response_with_headers" | grep 'HTTP/' | awk '{print $2}')
log_debug "response_status_code: $response_status_code"
if [ "$response_status_code" -eq 204 ]; then
Expand All @@ -83,6 +82,7 @@ declare -F check_org_membership >/dev/null || check_org_membership() {
echo 1
fi
}

check_if_valid_org_user() {
if [ -n "$ghe_host" ]; then
log_debug "ghe_host provided - using $ghe_host"
Expand Down Expand Up @@ -144,13 +144,11 @@ check_if_valid_user() {
# Returns: 0 if the user is a member of the team, 1 if the user is not a member of the team, 2 if the request failed
#
declare -F check_team_membership >/dev/null || check_team_membership() {
set +e
gh_response_with_headers=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/orgs/$org/teams/$teams/memberships/$username" \
-i)
set -e
gh_response_with_headers=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/orgs/$org/teams/$teams/memberships/$username" \
-i)

response_status_code=$(echo "$gh_response_with_headers" | grep 'HTTP/' | awk '{print $2}')
response_state_json=$(echo "$gh_response_with_headers" | grep '.state')
Expand Down

0 comments on commit 71037af

Please sign in to comment.