Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Github API calls to allow for the new auth mechanism #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ When running the script for the first time, the user will be prompted to enter h

## Repositories Refresh

When cloning, if the repository already exists then the script will perfrom a `git pull` assuming that the remote is `origin` and will update the local `master branch
When cloning, if the repository already exists then the script will perfrom a `git pull` assuming that the remote is `origin` and will update the local `master` branch

## Installation

Expand All @@ -36,8 +36,6 @@ sudo wget -P /usr/local/bin https://raw.githubusercontent.com/SeedJobs/git-beam-

> Note: After first setup, you might need to source your .bash_profile, .bashrc or .zshrc in order for the variables export to take effect and not to be prompted again

![beam-it](https://camo.githubusercontent.com/cd17fa04b4f7840feecb85049c4f2341bfc388a39b2839aca3c118e5e3256986/68747470733a2f2f7332322e706f7374696d672e63632f6136717839627364742f6769742d6265616d2d69745f7075626c69632e676966)

```bash
Usage: git beam-it <options>
```
Expand All @@ -57,8 +55,6 @@ Usage: git beam-it <options>

If the paramteres `-t` and `-o` have been left empty, then the script will fetch the list of ogranisations and teams for that specific user, the user will then be prompted to enter the organisation name or team id or just skip to fetch all repositories.

![beam-it setup](https://camo.githubusercontent.com/8cb9cf235524b08d9b3a45e6839a6ff19aa87c892931b38b3f31bdfa33cda848/68747470733a2f2f692e696d6775722e636f6d2f527476567034562e676966)

### Examples:

```bash
Expand All @@ -77,8 +73,6 @@ git beam-it -d ~/temp -s -t

> the paramteres `-t` and `-o` are mutually exclusive .. make sure you only execute the command for a specific team or organisation.

![beam-it team](https://camo.githubusercontent.com/70b8e1b0ed22b70c42e9a8b04f9fb3b0828ebf8ae84f53f28168147ed7f30de5/68747470733a2f2f7332322e706f7374696d672e63632f3865787965667736392f6769742d6265616d2d69745f7465616d2e676966)

> beam-it prompts the user to select from his list of teams if no team id was defined

### Known Issues
Expand Down
28 changes: 19 additions & 9 deletions git-beam-it
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2059

#
# Beam-it: Bulk clone Github Repositories
Expand Down Expand Up @@ -75,20 +76,28 @@ set_environment_variable() {
# @function get_teams
# @description get the list of teams from Github profile for an organisation
get_teams() {
printf "We have noticed that you have specified the team ${YELLOW}-t${NC} flag, but have not defined a team\nHere are a list of your teams and their ids in case you did not know them:\n${MAGENTA}"
curl --silent https://api.github.com/user/teams?access_token=$GITRIEVAL_TOKEN | jq '.[] | .id, "name:" + .name, "organisation:" + .organization.login' | sed 'N;N;s/\n/ /g' | sed 's/\"//g'
printf "${YELLOW}Note: you need to provide the team id and not the team name${NC}\n"
printf "${NC}Press ${YELLOW}[ENTER]${NC} to skip the team flag and fetch all repositories for the user\n"
read -p "Which team id you wish to fetch repositories for: ? " -e TEAM
printf "%s ${YELLOW}%s${NC} %s\n" "We have noticed that you have specified the team" "-t" "flag but have not defined a team"
printf "%s${MAGENTA}\n\n" "Here are a list of your teams and their ids in case you did not know them:"

curl --silent -H "Authorization: token $GITRIEVAL_TOKEN" https://api.github.com/user/teams | jq '.[] | .id, "name:" + .name, "organisation:" + .organization.login' | sed 'N;N;s/\n/ /g' | sed 's/\"//g'

printf "\n\n${YELLOW}%s${NC}\n" "Note: you need to provide the team id and not the team name"
printf "%s${YELLOW}%s${NC}%s\n" "Press" "[ENTER]" "to skip the team flag and fetch all repositories for the user"

read -rp "Which team id you wish to fetch repositories for: ? " -e TEAM
}

# @function get_organisations
# @description get the list of organisation for a Github profile
get_organisations() {
printf "We have noticed that you have specified the organisation ${YELLOW}-o${NC} flag, but have not defined an organisation\nHere are a list of your organisations in case you did not know them:\n${MAGENTA}"
curl --silent https://api.github.com/user/orgs?access_token=$GITRIEVAL_TOKEN | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | gawk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w login | cut -d "|" -f2
printf "${NC}Press ${YELLOW}[ENTER]${NC} to skip the organisation flag and fetch all repositories for the user\n"
read -p "Which organisation you wish to fetch repositories for: ? " -e ORGANISATION
printf "%s ${YELLOW}%s${NC} %s\n" "We have noticed that you have specified the organisation" "-o" "flag, but have not defined an organisation"
printf "%s${MAGENTA}\n\n" "Here are a list of your organisations in case you did not know them:"

curl --silent -H "Authorization: token $GITRIEVAL_TOKEN" https://api.github.com/user/orgs | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | gawk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w login | cut -d "|" -f2

printf "\n${NC}Press ${YELLOW}[ENTER]${NC} to skip the organisation flag and fetch all repositories for the user\n"

read -rp "Which organisation you wish to fetch repositories for: ? " -e ORGANISATION
}

# @function get_repos
Expand Down Expand Up @@ -245,3 +254,4 @@ else
printf "%s${RED}%s${NC}%s\n" "Since no team or organisation were defined, retreiving" " ${TYPE} " "repositories for the user"
request_github_api "user/repos?type=${TYPE}"
fi