REST: Searching among repositories in which I am a member #139982
Unanswered
FaultyCrocodile
asked this question in
API and Webhooks
Replies: 1 comment
-
hey @FaultyCrocodile,
for example: import requests
# Replace 'your_token' with your GitHub personal access token
headers = {
'Authorization': 'Bearer your_token',
'Accept': 'application/vnd.github.v3+json'
}
owned_repos = requests.get('https://api.github.com/user/repos?type=owner', headers=headers).json()
collaborated_repos = requests.get('https://api.github.com/user/repos?type=collaborator', headers=headers).json()
org_repos = requests.get('https://api.github.com/user/repos?type=organization', headers=headers).json()
# Combine all repos
all_repos = owned_repos + collaborated_repos + org_repos
def search_repos(search_term):
return [repo for repo in all_repos if search_term.lower() in repo['name'].lower()]
search_results = search_repos('repo')
for repo in search_results:
print(repo['full_name']) [1] https://stackoverflow.com/questions/77536289/github-api-searching-in-repositories-where-user-has-read-write-or-admin-permiss If it's helpful, please mark it as an answer! 😴 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Select Topic Area
Question
Body
Hi there!
I was wondering if there is a reliable way to search repositories only from those I am a member of (so a union of three groups: repos that I own, repos from other users that I collaborated with, repos from organizations I am a member of) using the REST API.
Currently, it is possible to either list all repos for a user (
/user/repos?type=member
) or search in all available repositories (/search/repositories
). The latter is quite confusing: its scope includes all public repositories and there is no way of sorting the result to put repos related to me on the top.For example, my repos are:
And there is some publicly available repo that I have no relation to: Someone/repo1. I can list all my repos, getting repo2, repo3, repo4, repo5 and foo. I can search for a "repo", and get repo1, repo2, repo3, repo4, repo5. The desired search result would be repo2, repo3, repo4, repo5 (with an option to do the search on the GitHub side, of course)
Is it not supported (why? many other hostings do support it), or did I not find something?
Beta Was this translation helpful? Give feedback.
All reactions