connectors icon indicating copy to clipboard operation
connectors copied to clipboard

Check repo teams as well as collaborators

Open navarone-feekery opened this issue 9 months ago • 3 comments

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.

navarone-feekery avatar Apr 26 '24 16:04 navarone-feekery

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.

wangch079 avatar Apr 29 '24 04:04 wangch079

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

navarone-feekery avatar Apr 29 '24 08:04 navarone-feekery

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: https://github.com/elastic/connectors/blob/f4535d302b1bec97aab04ed6862b92eda6d3e5c7/.github/workflows/scripts/label_community_issues.py#L30-L33

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

wangch079 avatar Apr 29 '24 11:04 wangch079

@navarone-feekery should we close this PR?

artem-shelkovnikov avatar Jul 23 '24 11:07 artem-shelkovnikov