Is there a way to transfer all GitHub repositories owned by one user to another user? Is this functionality accessible by an admin (eg. on Enterprise, if the user can no longer access GitHub)?
GitHub has a convenient command-line tool: hub found at https://hub.github.com
I've written an example to move all repos from all your organisations to my_new_organisation_name:
#!/usr/bin/env bash
orgs="$(hub api '/user/orgs' | jq -r '.[] | .login')";
repos="$(for org in $orgs; do hub api '/orgs/'"$org"'/repos' | jq -r '.[] | .name';
done)"
for org in $orgs; do
for repo in $repos; do
( hub api '/repos/'"$org"'/'"$repo"'/transfer'
-F 'new_owner'='my_new_organisation_name' | jq . ) &
done
done
For users rather than organisation, set my_new_organisation_name to the replacement username, remove the outer loop, and replace the repos= line with:
repos="$(hub api /users/SamuelMarks/repos | jq -r '.[] | .name')"
EDIT: Found a GUI if you prefer https://stackoverflow.com/a/54549899
Related
I'm looking for a way to get both the version number and license details from a repo providing I have the URL for the Repo. I have a way at the moment that doesn't work for all repos I am reviewing but it's basically html scraping.
I assume there is an API example somewhere that pulls these details?
some random examples
https://github.com/Microsoft/Terminal
https://github.com/leoasis/redux-immutable-state-invariant
https://github.com/zeroclipboard/zeroclipboard
What version do you need ? If a package.json file is present, you can use it and get the version in it:
curl -sL https://raw.githubusercontent.com/leoasis/redux-immutable-state-invariant/master/package.json | jq -r '.version'
For the latest release tag name (aka version), use
curl -sL https://api.github.com/repos/Microsoft/Terminal/releases/latest | jq -r '.tag_name'
To retreive the license, use the Github API and go to https://api.github.com/repos/zeroclipboard/zeroclipboard/license, e.g.
curl -sL https://api.github.com/repos/zeroclipboard/zeroclipboard/license | jq -r '.license.name'
`
How do I batch archive my repositories? I'd preferably want to be able to sort through them and figure out a way to not archive my active repositories.
I have hundreds of old GitHub repositories in my account since before the GitHub notifications feature, and now I get vulnerability notifications for all of them. Here's what my notifications look, for projects that were last used maybe 6 years ago:
You can use the GitHub API along with two tools to achieve this. I'll be using:
Hub, but you can make direct API calls
jq, but you can use any JSON parser
Here's how:
Fetch a list of all the GitHub repositories in our account, and saving them in a file:
hub api --paginate users/amingilani/repos | jq -r '.[]."full_name"' > repos_names.txt
Go through that file manually, remove any repositories you don't want to archive
Archive all the repositories in the file:
cat repos_names.txt | xargs -I {} -n 1 hub api -X PATCH -F archived=true /repos/{}
Note: since 2020:
gh repo list has been released (with gh 1.7.0 in commit 00cb921, Q1 2021): it does take pagination in account, as it is similar to an alias like:
set -e
repos() {
local owner="${1?}"
shift 1
gh api graphql --paginate -f owner="$owner" "$#" -f query='
query($owner: String!, $per_page: Int = 100, $endCursor: String) {
repositoryOwner(login: $owner) {
repositories(first: $per_page, after: $endCursor, ownerAffiliations: OWNER) {
nodes {
nameWithOwner
description
primaryLanguage { name }
isFork
pushedAt
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
' | jq -r '.data.repositoryOwner.repositories.nodes[] | [.nameWithOwner,.pushedAt,.description,.primaryLanguage.name,.isFork] | #tsv' | sort
}
repos "$#"
gh repo list --no-archived can limit the list to your not-yet-archived repositories
gh repo archive can then, for each element of that list, archive the GitHub repository.
wolfram77 also proposes in the comments:
gh repo list <org> | awk '{NF=1}1' | \
while read in; do gh repo archive -y "$in"; done
Using only gh.
gh repo list --no-archived --limit 144 --visibility public --source --json nameWithOwner --jq ".[].nameWithOwner" > repos_names.txt
Set --limit to the number of repositories you have.
Use vim to delete line which you don't want to archive by pressing dd on the line:
vim repos_names.txt
Run the the following command to arrive them
cat repos_names.txt | while read in; do gh repo archive -y "$in"; done
Clear after:
rm repos_names.txt
From the answer to a related question I know it's possible to batch clone repositories based on a GitHub search result:
# cheating knowing we currently have 9 pages
for i in {1..9}
do
curl "https://api.github.com/search/repositories?q=blazor+language:C%23&per_page=100&page=$i" \
| jq -r '.items[].ssh_url' >> urls.txt
done
cat urls.txt | xargs -P8 -L1 git clone
I also know that the Hub client allows me to make API calls.
hub api [-it] [-X METHOD] [-H HEADER] [--cache TTL] ENDPOINT [-F FIELD|--input FILE]
I guess the last step is, how do I archive a repository with Hub?
You can update a repository using the Update a Repository API call.
I put all my repositories in a TMP variable in the following way, and ran the following:
echo $TMP | xargs -P8 -L1 hub api -X PATCH -F archived=true
Here is a sample of what the $TMP variable looked like:
echo $TMP
/repos/amingilani/9bot
/repos/amingilani/advent-of-code-2019
/repos/amingilani/alan
/repos/amingilani/annotate_models
Is there any way to export the list of consumer accounts from the google cloud admin console ( Transfer tool for unmanaged users) . Or I have to do copy/paste .
I was looking for a way to get : user email // Request Status // Last sent // Request already sent.
Thanks a lot.
If you want to export all the accounts in the project you can do the following:
gcloud projects get-iam-policy PROJECT-ID
To get all the accounts:
gcloud projects get-iam-policy PROJECT_ID | awk -F ":" '{print $2}' | grep '#'
To get the ones that are not service accounts (not managed):
gcloud projects get-iam-policy PROJECT_ID | awk -F ":" '{print $2}' | grep '#' | grep --invert-match "serviceaccount.com"
There's no API for the transfer tool for unmanaged users, and there's no option to export the list from the UI.
Here's my query to the GitHub API
curl -i -u {user} https://api.github.com/orgs/{org}/repos?type=all
But this does not list all repos for this organization that I have access to. Specifically, it does not list repos in the organization that are part of a team that I am a member of.
If I were to query
curl -i -u {user} https://api.github.com/teams/{teamid}/repos
I would see the missing repos. If I were to navigate to github.com, I would see both private organization repos and my team repos next to each other on the same page. Is there a way to get all of these repos in the same API query?
You can use the below command
gh repo list {organization-name}
before this login with below command
gh auth login
github.com/cli/cli
I apologize. It was listing all my repos...on subsequent pages. Learning about "page=" and "per_page=" was all I needed, and now I can see all of the repos I need.
To add to original answer, below command can be used if there are many repositories and you wanted to fetch required number of repos. Without -L flag it returns 30 items by default.
gh repo list <org> -L <#>
If you have gh, the github cli (https://cli.github.com/) and jq (https://stedolan.github.io/jq/) you can do this:
gh repo list $ORG -L $COUNT --json name | jq '.[].name' | tr -d '"'
where $ORG is your organization name and $COUNT is the max number of repos returned
Download the official gh cli, the github cli (https://cli.github.com/)
gh repo list $ORG -L $COUNT --json name --jq '.[].name'
Set $ORG equal to your organization name, and $COUNT to be the amount of Repos you want to list. (Set $COUNT equal to the amount of repos in the organization if you want to list them all)
curl -i -u "username":"password" https://your_git_url.com/organization_name | grep "codeRepository" | awk -F '"' '{print $6}'
Have you tried setting the "per_page"-attribute to "0"? I have seen some APIs using a default value of for example 20, but if you activately set it to 0, like ?per_page=0 you get all pages.