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

Check repo teams as well as collaborators #2455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

navarone-feekery
Copy link
Contributor

Alters the action that applies community labels to check against a repo's members as well as collaborators.

Previously API failures were resulting in labels being applied, so that should no longer be an issue also.

@wangch079
Copy link
Member

The [List repository collaborators](https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#list-repository-collaborators) API list team members as well:

For organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.

And more effectively, I think you can use Check if a user is a repository collaborator API directly.

@navarone-feekery
Copy link
Contributor Author

navarone-feekery commented Apr 29, 2024

@wangch079 I know the documentation states that those endpoints work, but these don't seem to work as expected.

For list repository collaborators, running the following;

gh api -XGET /repos/elastic/connectors/collaborators --jq '.[] | .login' >> file.json

Returns only 60 usernames. Mine for example is not included in the list. It also doesn't include outside contributors (e.g. Crest). I can only get those if I add affiliation=outside to the URL params.

For checking directly if a user is a collaborator;

gh api -i /repos/elastic/connectors/collaborators/navarone-feekery

Calling this locally from my machine returns a 204 (expected response). However, when I did this as a github action within connectors, it failed. This is despite the fact that it works on my own repo I tested it on. It is weird that it works locally. Maybe the github token provided to actions didn't give enough permissions 🤔

@wangch079
Copy link
Member

Hi @navarone-feekery , I tested the Check if a user is a repository collaborator API locally as well, with some users from elastic, our team, Crest, and non-collaborators, and they all return expected results.

I suggest you print the exception and status code here:

except BadRequest as e:
# if this fails we want it to be noisy, so no try/except
print("User is not a collaborator, applying labels...")
await gh.post(f"/repos/{REPO}/issues/{NUMBER}/labels", data={"labels": LABELS})

A non-collaborator response should return 404, and gidgethub returns BadRequest for all response status code >= 400 but not 422

I suspect it raised BadRequest for status code other than 404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants