Skip to content

Commit

Permalink
Merge pull request #2064 from conda-forge/allow-tokens-if-have
Browse files Browse the repository at this point in the history
fix: use gh token if we have one
  • Loading branch information
beckermr authored Sep 18, 2024
2 parents 8cf70ab + 270f439 commit bc70d35
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
34 changes: 30 additions & 4 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import os
import sys
from collections.abc import Mapping
from functools import lru_cache
from glob import glob
from inspect import cleandoc
from pathlib import Path
from textwrap import indent
from typing import Any, List, Optional, Tuple

import github
import github.Auth
import jsonschema
import requests
from conda_build.metadata import (
Expand Down Expand Up @@ -370,12 +373,35 @@ def lintify_meta_yaml(
return lints, hints


# the two functions here allow the cache to refresh
# if some changes the value of os.environ["GH_TOKEN"]
# in the same Python process
@lru_cache(maxsize=1)
def _cached_gh_with_token(token: str) -> github.Github:
return github.Github(auth=github.Auth.Token(token))


def _cached_gh() -> github.Github:
return _cached_gh_with_token(os.environ["GH_TOKEN"])


def _maintainer_exists(maintainer: str) -> bool:
"""Check if a maintainer exists on GitHub."""
return (
requests.get(f"https://api.github.com/users/{maintainer}").status_code
== 200
)
if "GH_TOKEN" in os.environ:
# use a token if we have one
gh = _cached_gh()
try:
gh.get_user(maintainer)
except github.UnknownObjectException:
return False
return True
else:
return (
requests.get(
f"https://api.github.com/users/{maintainer}"
).status_code
== 200
)


def run_conda_forge_specific(
Expand Down
23 changes: 23 additions & 0 deletions news/use-token.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed linter to use a GitHub Token if one is available. (#2064)

**Security:**

* <news item>

0 comments on commit bc70d35

Please sign in to comment.