Reputation: 17997
Following this documentation: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows
Fetching /repos/{owner}/{repo}/actions/workflows
should return the list of all workflows for a repository. This works fine for public repositories.
But, I couldn't figure out how to do it for private repositories, there is no token
header or anything similar that might be used for authentication.
Does anyone have an example for private repositories?
Upvotes: 0
Views: 3194
Reputation: 17997
@VonC answer's explains how to do it using Basic Auth. The below answer explains how to do it using the token
Authorization header and Node.js.
const response = await fetch(GITHUB_API_LIST_PROJECT_WORKFLOWS, {
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
},
});
Where GITHUB_API_LIST_PROJECT_WORKFLOWS
is a token generated at https://github.com/settings/tokens that contains full repo
and workflow
scopes.
Where GITHUB_API_LIST_PROJECT_WORKFLOWS
is a url of the form /repos/{owner}/{repo}/actions/workflows
, as described in https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows.
Upvotes: 1
Reputation: 1324935
The "If the repository is private you must use an access token with the repo scope" part of the documentation should refer to "Getting started with the REST API / Using personal access tokens"
The easiest and best way to authenticate with the GitHub API is by using Basic Authentication via OAuth tokens.
OAuth tokens include personal access tokens.
Example:
curl -i -u username:$token https://api.github.com/repos/{owner}/{repo}/actions/workflows
Upvotes: 3