0

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?

Vadorequest
  • 16,593
  • 24
  • 118
  • 215

2 Answers2

3

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried to use this solution and couldn't make it work (using node.js). But I don't know for sure that how I did was the right way to do it. Instead, I used a similar approach with `token` authorization header, which proved to work perfectly. – Vadorequest Dec 26 '20 at 15:56
1

@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.

Vadorequest
  • 16,593
  • 24
  • 118
  • 215