I want to add a group as a collaborator to my github repo
Docs page is missing this part. I can successfully add a person as a collaborator using this request
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/collaborators/USERNAME \
-d '{"permission":"permission"}'
but when I want to add a group(created under same organization) – I can't
Is there a possibility to do that?
The answer is to go from another end:
add repo to the team. Here are API references
https://docs.github.com/en/rest/reference/teams#add-or-update-team-repository-permissions
Related
Monthly I receive several invitations to be a collaborator of several Github repositories, unfortunately sometimes I miss the 7 days time to accept the invitations and as a consequence the invitations expire, making it impossible for me to access the repositories
I have tried to automate the invitations through GitHubActions but there is no such option.
Please, does anyone know how I can automate the acceptance of the invitations, so they will not expire after 7 days, which is the maximum time that Github grants before the invitations expire?
I have tried to automate the invitations through GitHubActions but there is no such option.
You can test out the GitHub Action kbrashears5/github-action-auto-accept-collabs which should auto accept all collaboration invites.
It does:
get all repository invites for [${USERNAME}]
curl -X GET -H "Accept: application/vnd.github.v3+json" -u ${USERNAME}:${GITHUB_TOKEN} \
--silent ${GITHUB_API_URL}/user/repository_invitations | \
jq '.[].id'
Accept each invite:
curl -d #- \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-u ${USERNAME}:${GITHUB_TOKEN} \
--silent \
${GITHUB_API_URL}/user/repository_invitations/${invite}
Star a topic can be done on the website. But how to do the same operation via GitHub API v3 or v4? I read through the reference but got no clues.
For the v3 REST API it's documented at Star a repository for the authenticated user
The curl example is:
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/starred/octocat/hello-world
But this doesn't show how to insert your token, so you actually need something more like:
curl \
-X PUT \
-H "Authorization: token $GITHUB_API_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/starred/octocat/hello-world
Where GITHUB_API_TOKEN has been previously set like:
GITHUB_API_TOKEN="ghp_16C7e42F292c6912E7710c838347Ae178B4a"
Per comments to this earlier question how to star a repo with github api make sure that the token used has the correct permissions to do the starring, which means having the repo scope (or at least repo_public) enabled.
I'd also love to know how to do this with the v4 GraphQl API.
I want to know how to get this data from the GitHub API.
I know I can get this data as raw but is there any way to get this using GitHub API?
Here is the requested file:
https://github.com/graphql-compose/graphql-compose-examples/blob/master/examples/northwind/data/csv/employees.csv
As seen here, try
curl -GLOf -H "Authorization: token ${GITHUB_TOKEN?not set}" \
-H "Accept: application/vnd.github.v4.raw" \
"https://api.github.com/repos/$ORG/$REPO/contents/$FILEPATH" -d ref="$REVISION"
In your case, for a public repository:
curl -GLOf -H "Accept: application/vnd.github.v4.raw" \
"https://api.github.com/repos/graphql-compose/graphql-compose-examples/contents/examples/northwind/data/csv/employees.csv"
I just tested it, and got a file employees.csv with its raw content in it.
Is there any option to recover Personal Access Token in Github?
Because my app is using the PAT in composer and I don't want to replace it.
You would need to replace it (OAuth Authorizations), since a token cannot be accessed after the generation step.
In a bash shell:
curl https://api.github.com/authorizations \
-X POST \
--user "YourGitHubUsername" \
--data '{"scopes":["gist","repo],"note":"new token"}'
(replace "new token" by something more meaningful)
I have a code in Github repo and wants to clone/copy it to the Azure repository, Is there any way to do it via Curl
Is there any way to do it via Curl
Yes. The method exists.
You need to use curl to run the following Rest API to create Other Git Service connection.
Post https://dev.azure.com/{Organization Name}/_apis/serviceendpoint/endpoints?api-version=6.0-preview.4
curl example:
curl -X POST \
-u USERName:PAT "https://dev.azure.com/org/_apis/serviceendpoint/endpoints?api-version=6.0-preview.4" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"authorization":{"scheme":"UsernamePassword","parameters":{"username":"{User name}","password":"{Password}"}},
"data":{"accessExternalGitServer":"true"},
"name":"{name}",
"serviceEndpointProjectReferences":[{"description":"","name":"{Service connection name}","projectReference":{"id":"{Project Id}","name":"{Project Name}"}}],
"type":"git",
"url":"{Target Git URL}",
"isShared":false,
"owner":"library"
}'
Then you could use the importRequests Rest API to import the Github Repo to Azure Repo.
Post https://dev.azure.com/{Organization Name}/{Project Name}/_apis/git/repositories/{Repo Name}/importRequests?api-version=5.0-preview.1
For more detailed info, you could refer to my another ticket: Get github repository using Azure devops REST API
This method is more complicated. I suggest that you could directly import the github repo with the Import repository option in Azure Repo.
You could import the clone URL and auth info, then the repo will be directly cloned to Azure Repo.