Skip to content
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
1 change: 1 addition & 0 deletions __tests__/utils/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ describe('authorization policies', () => {
['a root OWNERS reviewer', { owners: 'reviewers:\n - alice\n' }, { anyone: true, collaborators: false, members: false, trusted: true }],
['a root OWNERS approver', { owners: 'approvers:\n - alice\n' }, { anyone: true, collaborators: false, members: false, trusted: true }],
['nobody in particular', { owners: 'approvers:\n - bob\n' }, { anyone: true, collaborators: false, members: false, trusted: false }],
['nobody, with a 0-byte root OWNERS file', { owners: '' }, { anyone: true, collaborators: false, members: false, trusted: false }],
['nobody, with no root OWNERS file', {}, { anyone: true, collaborators: false, members: false, trusted: false }],
] as const)('%s', async (_, who, want) => {
const fixture: { users?: readonly string[], member?: boolean, collaborator?: boolean, owners?: string } = who
Expand Down
7 changes: 7 additions & 0 deletions __tests__/utils/ownersAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ describe('assertAuthorizedByOwnersOrMembership on a pull request', () => {
)
})

it('treats a 0-byte OWNERS file as listing nobody', async () => {
server.use(...prHandlers({ OWNERS: '' }, ['src/file1.txt']))
await expect(authorize('approvers', 'alice')).rejects.toThrow(
'alice is not an approver for any changed file',
)
})

it('requests the tree recursively and only fetches OWNERS blobs in ancestor directories', async () => {
const observeTree = new utils.ObserveRequest()
const observeDocsBlob = new utils.ObserveRequest()
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41941,7 +41941,7 @@ function isOwnersPath(path) {
}
function decode(data, path) {
const file = data;
if (!file.content || !file.encoding) {
if (file.content === undefined || !file.encoding) {
throw new Error(`invalid OWNERS file returned from GitHub API for ${path}`);
}
return external_node_buffer_.Buffer.from(file.content, file.encoding).toString();
Expand Down Expand Up @@ -42528,7 +42528,7 @@ async function retrieveOwnersFile(octokit, context) {
}
throw new Error(`error checking for an OWNERS file at the root of the repository: ${e}`);
}
if (!data.content || !data.encoding) {
if (data.content === undefined || !data.encoding) {
throw new Error(`invalid OWNERS file returned from GitHub API: ${data}`);
}
const decoded = external_node_buffer_.Buffer.from(data.content, data.encoding).toString();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
* @param octokit - a hydrated github client
* @param context - the github actions event context
* @param issueNum - the issue or pr number this runtime is associated with
* @param args - the users to check auth on

Check warning on line 194 in src/utils/auth.ts

View workflow job for this annotation

GitHub Actions / build-test

Expected @PARAM names to be "octokit, context, issueNum, user". Got "octokit, context, issueNum, args"
*/
export async function checkCommenterAuth(
octokit: Octokit,
Expand Down Expand Up @@ -490,7 +490,7 @@
)
}

if (!data.content || !data.encoding) {
if (data.content === undefined || !data.encoding) {
throw new Error(`invalid OWNERS file returned from GitHub API: ${data}`)
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/owners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function isOwnersPath(path: string): boolean {

function decode(data: unknown, path: string): string {
const file = data as { content?: string, encoding?: string }
if (!file.content || !file.encoding) {
if (file.content === undefined || !file.encoding) {
throw new Error(`invalid OWNERS file returned from GitHub API for ${path}`)
}
return Buffer.from(file.content, file.encoding as BufferEncoding).toString()
Expand Down
Loading