GitHub
feu.github ¶
Contain GitHub utility functions.
feu.github.build_github_headers ¶
build_github_headers() -> dict[str, str]
Build the HTTP headers to call the GitHub REST API.
The GITHUB_TOKEN environment variable is used to authenticate the
request if it is set.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The HTTP headers to use to call the GitHub API. |
Example
>>> from feu.github import build_github_headers
>>> headers = build_github_headers()
feu.github.display_repos_summary ¶
display_repos_summary(
repos: Sequence[dict[str, Any]],
) -> None
Display repository information in a readable format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos
|
Sequence[dict[str, Any]]
|
List of repository dictionaries from GitHub API. |
required |
Example
>>> from feu.github import fetch_github_repos, display_repos_summary
>>> repos = fetch_github_repos(owner="durandtibo") # doctest: +SKIP
>>> display_repos_summary(repos) # doctest: +SKIP
feu.github.fetch_github_metadata
cached
¶
fetch_github_metadata(
owner: str, repo: str
) -> dict[str, Any]
Get the GitHub repo metadata.
The metadata is read from GitHub API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
str
|
The owner of the repo. |
required |
repo
|
str
|
The repo name. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The repo metadata. |
Example
>>> from feu.github import fetch_github_metadata
>>> metadata = fetch_github_metadata(owner="durandtibo", repo="feu") # doctest: +SKIP
feu.github.fetch_github_repos
cached
¶
fetch_github_repos(
owner: str,
) -> tuple[dict[str, Any], ...]
Get the GitHub repo metadata.
The metadata is read from GitHub API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
str
|
The owner of the repo. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], ...]
|
The repo metadata. |
Example
>>> from feu.github import fetch_github_repos
>>> repos = fetch_github_repos(owner="durandtibo") # doctest: +SKIP
feu.github.sort_repos_by_key ¶
sort_repos_by_key(
repos: Sequence[dict[str, Any]],
*,
key: str,
reverse: bool = False
) -> list[dict[str, Any]]
Sort repositories by a given key.
Repositories without the key, or with a None value for the
key, are placed at the end in their original order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos
|
Sequence[dict[str, Any]]
|
List of repository dictionaries from GitHub API. |
required |
key
|
str
|
Key to sort. |
required |
reverse
|
bool
|
If True, sort in descending order. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of repository dictionaries sorted in ascending order |
list[dict[str, Any]]
|
(or descending if reverse=True). Repositories without the key, or |
list[dict[str, Any]]
|
with a |
list[dict[str, Any]]
|
original order. |
Example
>>> from feu.github import sort_repos_by_key
>>> repos = [{"name": "zoo"}, {"name": "alpha"}, {"id": 1}]
>>> sort_repos_by_key(repos, key="name")
[{'name': 'alpha'}, {'name': 'zoo'}, {'id': 1}]
>>> sort_repos_by_key(repos, key="name", reverse=True)
[{'name': 'zoo'}, {'name': 'alpha'}, {'id': 1}]