Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for REPOSITORIES regex with app installation tokens #117

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A Github Action that can sync secrets from one repository to many others. This a

### `github_token`

**Required**, Token to use to get repos and write secrets. `${{secrets.GITHUB_TOKEN}}` will **not** work as it does not have the necessary scope for other repositories. This token should have the full "repo" scope. In older instances of GitHub, a fine-grained token may not support the required GraphQL API and a "Classic" personal access token would be required. As this is deprecated, please try a fine-grained token first.
**Required**, Token to use to get repos and write secrets. `${{secrets.GITHUB_TOKEN}}` will **not** work as it does not have the necessary scope for other repositories. This should be a classic PAT with the full "repo" scope, or a fine-grained PAT or app installation token with "Secrets" set to "Read and write". In older instances of GitHub, a fine-grained token may not support the required GraphQL API and a "Classic" personal access token would be required. As this is deprecated, please try a fine-grained token first.

### `repositories`

Expand Down
47 changes: 44 additions & 3 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ afterAll(() => {
});

describe("listing repos from github", () => {
const pageSize = 3;
const per_page = 3;
beforeEach(() => {
nock("https://api.github.com")
.get(/\/user\/repos?.*page=1.*/)
Expand All @@ -72,7 +72,7 @@ describe("listing repos from github", () => {
const repos = await listAllMatchingRepos({
patterns: [".*"],
octokit,
pageSize,
per_page,
});

expect(repos.length).toEqual(3);
Expand All @@ -82,11 +82,52 @@ describe("listing repos from github", () => {
const repos = await listAllMatchingRepos({
patterns: ["octokit.*"],
octokit,
pageSize,
per_page,
});

expect(repos.length).toEqual(3);
});

test("listAllReposAccessibleToInstallation matches patterns", async () => {
// Shadow original octokit with install token based one
const origConfig = config.getConfig();
(config.getConfig as jest.Mock).mockImplementation(() => ({
...origConfig,
GITHUB_TOKEN: "ghs_installation_token",
}));
const octokit = DefaultOctokit({
auth: "",
});

// Setup app install endpoint
nock("https://api.github.com")
.get(/\/installation\/repositories?.*page=1.*/)
.reply(200, {
repositories: [
fixture[0].response,
fixture[0].response,
{ archived: true, full_name: "foo/bar" },
],
});

nock("https://api.github.com")
.get(/\/installation\/repositories?.*page=2.*/)
.reply(200, {
repositories: [
fixture[0].response,
fixture[0].response, // One more repo to distinguish installation endpoint from user endpoint
],
});

// Query installation endpoint
const repos = await listAllMatchingRepos({
patterns: ["octokit.*"],
octokit,
per_page,
});

expect(repos.length).toEqual(4);
});
});

describe("getting single repos from github", () => {
Expand Down
Loading
Loading