Add team qualifier to code search 👥 👥 #9023
Replies: 14 comments 18 replies
-
Hi @look 👋🏼 |
Beta Was this translation helpful? Give feedback.
-
Hey @Avivhdr, that's a nice idea. We don't currently have team info in the index right now. As a possible workaround, teams can create custom scopes with repositories relevant to their team. Click on the scope dropdown to the left of the search box, scroll to the bottom and click "Custom scopes". Once a team creates a custom scope, they can share it by just sharing the scope's URL. Obviously not as good as having a |
Beta Was this translation helpful? Give feedback.
-
I see this request duplicated in a few places, but would also appreciate it. |
Beta Was this translation helpful? Give feedback.
-
Would love to see this feature implemented. Filtering on repositories works but not feasible to maintain long term. Until this is implemented I wrote a small node app which will query the Github API for the repositories belonging to a team and create queries to filter on them. This should at least make keeping the custom scopes up to date a bit easier even though it does not solve the issue of having to query multiple times if your team has a lot of repositories as it is still limited by the 500 query character limit (it will generate multiple queries if a query becomes too long) |
Beta Was this translation helpful? Give feedback.
-
Is there any movement on this issue? |
Beta Was this translation helpful? Give feedback.
-
I would also be interested in the ability to search within my team's repositories. I tried looking for custom scopes, but can't find that feature in the search UI. When we were using Github Enterprise, my team had our own org which made searching easy. Now that we've migrated to Github.com, the org is company wide. I'm in a situation were I'd like to quickly check my team's repos for usage of a particular string, and don't have a good way to do that. |
Beta Was this translation helpful? Give feedback.
-
Any news here? |
Beta Was this translation helpful? Give feedback.
-
Implementing this as described by the OP would be amazing for us. +1 from me! |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? It's been a long time since I'm waiting for it already 😁 |
Beta Was this translation helpful? Give feedback.
-
@colinwm What gives? This feature is a no-brainer. It's shocking that the teams concept was launched without this, and appalling that years later is still doesn't exist. |
Beta Was this translation helpful? Give feedback.
-
Is this feature coming? Any possible workarounds it would be super useful and time saving when a code needs to be searched in particular team repos. |
Beta Was this translation helpful? Give feedback.
-
It's a must for any multi-team organization. Otherwise code search is close to useless... coming from Azure DevOps it's really a pain. |
Beta Was this translation helpful? Give feedback.
-
@ranasimpplr on the subject of workarounds, I've been using a Python script and PyGithub to do this search. It adds edit: looking at the Github API, I realized that I was being too conservative with the character length for queries. The 256 character limit mentioned does not include qualifiers. There is some kind of overall character limit beyond the 4000 repository limit mentioned on that page, but I don't know what that overall limit actually is. Play around with values maybe? https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#limitations-on-query-length from github import Github
from github.Repository import Repository
from pprint import pprint
def github_code_search_repos(github: Github, queries: list[str]) -> list[Repository]:
"""Executes the provided queries, and combines results
:param Github github: Github API class from PyGithub
:param list[str] queries: Queries to execute
:return list[Repository]: Combined repositories returned by queries
"""
total_queries = len(queries)
results = []
# run all queries
# no retry logic because that's now implemented in PyGithub
for index, query in enumerate(queries):
print(f'Running query {index + 1} of {total_queries}')
response = g.search_code(query)
results.extend(response)
return [result.repository for result in results]
def search_git_by_team(github: Github, search_query: str, org_name: str, team_name: str) -> set[str]:
"""Searches Github code using the provided query in repos for the specified org and team
:param Github github: Github API class from PyGithub
:param str search_query: Query for Github code search
:param str org_name: Github Org to search
:param str team_name: Team within Org whose repos should be searched
:return set[str]: A set of URLs for repos that had results for the Github code search
"""
# Get repos to search
org = g.get_organization(org_name)
team = org.get_team_by_slug(team_name)
repos = team.get_repos()
repo_full_names = [repo.full_name for repo in repos]
print(f'Found {len(repo_full_names)} repos for team {team_name} in {org_name}')
# Determine how many characters we have available in search string for "repo:" qualifiers after search term(s)
max_qualifier_length = 255 - len(search_query)
# Combine repos into queries
queries = []
while repo_full_names:
# Start building a new query
current_qualifiers = [f'repo:{repo_full_names.pop()}']
current_length = len(current_qualifiers[0])
# Add more repos to the current query
while repo_full_names:
next_repo = repo_full_names.pop()
new_length = len(next_repo) + current_length + 6 # six characters for " repo:"
# check if new qualifier would be too long
if new_length <= max_qualifier_length:
current_qualifiers.append(f'repo:{next_repo}')
current_length = new_length
else:
# if too long, requeue next repo and stop adding more
repo_full_names.append(next_repo)
break
# Character limit hit, build the complete query
current_qualifiers.append(search_query)
qualified_query = ' '.join(current_qualifiers)
queries.append(qualified_query)
# Queries assembled to cover all team's repos, now execute and combine results
print(f'Condensed repos to {len(queries)} queries.')
return set(repo.html_url for repo in github_code_search_repos(github, queries))
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('search_string', help='Search term for Github code search')
parser.add_argument('target_org', help='Github Org to search')
parser.add_argument('target_team', help='Team whose repos should be searched')
args = parser.parse_args()
with open('.github_access_token', 'r') as f:
access_token = f.readline().strip()
g = Github(access_token)
results = search_git_by_team(g, args.search_string, args.target_org, args.target_team)
pprint(results) |
Beta Was this translation helpful? Give feedback.
-
Github also recommends grouping multiple teams into an organization, so it would be nice if they would make their preferred organizational structure actually usable from a search standpoint. |
Beta Was this translation helpful? Give feedback.
-
Hello Github team 👋🏼
Please add an option to add a
team
qualifier to the code search.In our organization, we have countless repositories and teams.
We need to search for a specific use of a method inside our repositories and notify each team that uses this method that they need to deprecate it.
If I had the
team
qualifier, each team could searcharray.badMethod team:team-x
and find a list that contains all (and only) the instances of that method that they need to work on.Currently, if I search for and find the method in a repository, even after opening and viewing the repository I can't see which team owns it and I have to rely on the
contributors
section, which at times contains members that are no longer in the organization.There is an open issue on that so I would like it here as well 😉
#9021
Thank you 🙏🏼
Beta Was this translation helpful? Give feedback.
All reactions