galaxyproject / galaxyproject/planemo

mulled-search gives error when searching GitHub sources due to lack of valid token

Open
#1,535 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
110
Forks
102
Avg merge
4d 21h
Merged PRs (30d)
13

Description

When running `mulled-search -o biocontainers -s minimap2=2.28` the GitHub API error is raised due to lack of the token. Github now requires a valid token to search code which triggers error

`requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.github.com/search/code?q=minimap2=2.28+in:path+repo:bioconda/bioconda-recipes+path:recipes`

To solve this one needs to import `GITHUB_TOKEN` global variable from the environment and modify the `mulled_search.py` around line 160 `def get_json(self, search_string)` to add header with the token to correctly query GitHub API. GitHub **classical** token needs to generated in your account at https://github.com/settings/tokens/

Update the code as follows:

```
def get_json(self, search_string):
"""
Takes search_string variable and return results from the bioconda-recipes github repository in JSON format

DEPRECATED: this method is currently unreliable because the API query
sometimes succeeds but returns no items.
"""

github_token = os.getenv("GITHUB_TOKEN")
headers = {
"Accept": "application/vnd.github+json"
}

if github_token:
headers["Authorization"] = f"Bearer {github_token}"

response = requests.get(
f"https://api.github.com/search/code?q={search_string}+in:path+repo:bioconda/bioconda-recipes+path:recipes",
headers=headers,
timeout=MULLED_SOCKET_TIMEOUT,
)

...
```

After this modification all works great and the following output is obtained

```
$ mulled-search -o biocontainers -s minimap2=2.28
The query returned the following result(s).
LOCATION NAME VERSION COMMAND
conda minimap2 2.28--h577a1d6_4 conda install -c bioconda minimap2=2.28=h577a1d6_4
conda minimap2 2.28--he4a0461_0 conda install -c bioconda minimap2=2.28=he4a0461_0
conda minimap2 2.28--he4a0461_1 conda install -c bioconda minimap2=2.28=he4a0461_1
conda minimap2 2.28--he4a0461_2 conda install -c bioconda minimap2=2.28=he4a0461_2
conda minimap2 2.28--he4a0461_3 conda install -c bioconda minimap2=2.28=he4a0461_3

The following recipes were found in the bioconda-recipes repository which exactly matched one of the search terms:
QUERY LOCATION
```

I noticed that this issue is linked to `galaxy-tool-util` package which contains all `mulled-*` scripts. I was using v24.2.3 of `galaxy-tool-util` and `galaxy-util`

Contributor guide

Open the contributing guide

Research direction

The affected entry point is mulled_search.py in the galaxy-tool-util package, especially get_json(search_string) around line 160; start by locating that function and reproducing the shown mulled-search command. Done means GitHub code search accepts an optional GITHUB_TOKEN and the minimap2=2.28 query returns results without the 401 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, python
Domain
api, cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.