Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

feat: Add a script to see if the CLA check is required. #39

Merged
merged 5 commits into from
Nov 1, 2022

Conversation

feanil
Copy link
Contributor

@feanil feanil commented Oct 26, 2022

This adds the CLA check in a fairly generic way so that we can add other
checks and fixes as we figure them out.

This adds the CLA check in a fairly generic way so that we can add other
checks and fixes as we figure them out.
For the CLA check to be properly enforced, two things need to be true.

1. The check has to be a required check so that changes can't be merged
  without it passing.

2. The `cla-checker` team needs write access to the repo so that it can
  actually post the check results on PRs in the repo.
  * The `cla-checker` teams is just the openedx-webhooks bot that
    currently posts the check status.

This change fixes the second issue, ensuring that the cla-checker team
has write(push) access to the repo.
self.team_setup_correctly = True
return (True, f"'{self.cla_team}' team has 'push' access.")

def dry_run(self):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it would make sense to make dry_run a member of the class instead of passing it around since it doesn't look like you're calling the fix method more than one way in the same run. I can see an argument for leaving it as is for manual testing, it really depends on how you expect it to be used.

Copy link

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, just the nit and you don't need the parens on your tuple returns (though I honestly don't know if that's a thing our tooling usually enforces, Black usually yells at me for it).

Copy link

@Carlos-Muniz Carlos-Muniz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Are there any tests or action runs showing that it works as intended?

Comment on lines 15 to 16
def __init__(self, api, org, repo):
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why specify this __init__ and not implement anything? You could give a default that assigns these attributes to member variables and then have subclasses implement their own customized ones and call this via super().__init__()

Comment on lines 18 to 19
def check(self):
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe run() instead of check() (given the class is Check)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also would pair better with dry_run, though if they share enough logic, you could make it a param to check instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I have this mixed up. dry_run() is for the fix() counterpart, and check() has no side-effects?

from ghapi.all import GhApi, paged


class Check:
Copy link
Contributor

@ormsbee ormsbee Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these comments I'm making, I'm assuming that this is something we're going to be building on in the future. If it's likely to only be used once or twice, it's probably not worth the effort to refactor around.

self.team_setup_correctly = False

def check(self):
is_required_check = self._check_cla_is_required_check()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the longer term, it might be worthwhile to think about decoupling the logic of "how does this check run" from "should this check run on this repo", since the latter is a policy decision that may be very separate from the logic of how to actually execute those checks.

Copy link
Contributor

@ormsbee ormsbee Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things that putting it in the same place makes me wonder off the top of my head is, "What is the expected result of check() if the repo doesn't pass the check, but it's also not a required check for this repo."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, not addressing this in this round but I'm thinking more about this and will probably add a separate function to see if it should run separate from whether or not the check would succeed. I'll probably try to make that change as I add more checks.

- Make the init function in the base class useful and call it.
- Add docstrings to better show intent of the different functions.
Feanil Patel added 2 commits November 1, 2022 09:57
Security forks are not like regular repositories in most of the ways we
care about.  In particular, you don't manage access to them via teams
the same way since they are linked to a security advisory.

For now we'll skip these for all checks but later it will probably make
sense to figure out a way for each check to evaluate a repo for whether
or not it should run on that repo, independent of whether or not it will
pass or fail if run.  This was great advice from Dave Ormsbee and we
can iterate on it futher as we add more checks.
* Fix a spelling issue in the check data.
* Extract restriction strings from input data.
* Fix an unformatted string.
@feanil feanil merged commit 86e27dd into main Nov 1, 2022
@feanil feanil deleted the feanil/cla_check branch November 1, 2022 15:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants