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

Support tracking state for multiple repos #97

Merged
merged 14 commits into from
Jun 28, 2022

Conversation

yasunariw
Copy link
Collaborator

@yasunariw yasunariw commented Dec 23, 2020

Description of the task

Separates config + pipeline status tracking by repository, so that the bot can send notifications for multiple repositories, each according to its own config file.

Changes:

  • Track separate config + state information for each repo
  • Give users the option to configure GitHub secrets per repo (see documentation/config_docs.md for details). Doesn't break existing deployments as this per-repo config is optional. This is now mandatory Support tracking state for multiple repos #97 (comment)
  • However, existing state.json files will be incompatible with new format

How to test

Existing tests should pass (make test). Also tested with staging workspace.

References

@yasunariw yasunariw force-pushed the yasu/upgrade-status-rules branch from b47ab24 to 24e0c4f Compare December 24, 2020 02:19
@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch from 0dce9e2 to 9112794 Compare December 24, 2020 03:16
@yasunariw yasunariw changed the base branch from yasu/upgrade-status-rules to master December 24, 2020 03:18
@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch 3 times, most recently from d983684 to 64c4582 Compare December 25, 2020 13:01
@yasunariw yasunariw marked this pull request as ready for review December 25, 2020 13:09
@yasunariw yasunariw requested a review from ygrek December 25, 2020 13:09
@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch from 64c4582 to bdaa5e8 Compare December 29, 2020 01:57
@yasunariw yasunariw removed the request for review from ygrek December 31, 2020 02:12
@yasunariw
Copy link
Collaborator Author

yasunariw commented Dec 31, 2020

Postponing this PR until remote config loading behavior is changed to fetch on startup

@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch 3 times, most recently from 6741fb6 to d306035 Compare January 5, 2021 06:11
@yasunariw yasunariw requested review from Khady and ygrek January 5, 2021 06:29
@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch 4 times, most recently from d3fe839 to 3e47dde Compare December 3, 2021 10:29
@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch from ec155eb to 1792647 Compare January 7, 2022 02:30
lib/state.ml Outdated
let empty : State_t.state = { pipeline_statuses = StringMap.empty; bot_user_id = None }
type t = {
state : State_t.state;
lock : Lwt_mutex.t;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lock because pipeline_statuses is a mutable field containing a string map (I think this was necessary even before multi-repo)

Copy link
Contributor

Choose a reason for hiding this comment

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

this must be a comment in code

@@ -2,19 +2,45 @@ open Base
open Common
open Devkit

let empty : State_t.state = { pipeline_statuses = StringMap.empty; bot_user_id = None }
type t = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

later should add mli and make opaque

@@ -85,16 +95,17 @@ let refresh_state ctx =
match get_local_file path with
| Error e -> fmt_error "error while getting local file: %s\nfailed to get state from file %s" e path
| Ok file ->
let state = State_j.state_of_string file in
let state = { ctx.state with state = State_j.state_of_string file } in
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

later should move some of this fn into state.ml

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe leave that as a comment in code

Comment on lines 58 to 57
## `allowed_repos`

Use this option to restrict incoming notifications from GitHub to approved repository URLs.

Repository URLs should be fully qualified (include the protocol), with no trailing backslash.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this second value is required. Aren't all the whitelisted repos already listed under repos?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was to 1) stay compatible with existing configs, 2) let repos be whitelisted without defining repo-specifc secrets, and 3) let whitelisting itself be optional. I could alternatively use repos as the whitelist (and expect null for whitelisted repos that use default secret), or rename to something less confusing like repo_secrets

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should break compatibility in such cases, or support two formats - legacy and new one (have one object per repository with secrets and any other configurations necessary per-repo)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Khady @rr0gi Hopefully after 1.5 years the stars will align for me to finally merge this.

I broke compatibility, now there is a single repos field. If empty then assumes single repo. Also I changed from object to list, to allow for repos that don't need to override any secrets.

233543c

@yasunariw yasunariw removed the request for review from ygrek May 5, 2022 02:57
yasunariw added 9 commits May 6, 2022 16:20
With repo-specific secrets, we'll need the repo name in order
to obtain the webhook token used for signature validation. So
parsing the request body for a GH payload needs to happen before,
not after, the signature check.
Define custom getters for retrieving GH secret values. As the
getter for each token type defaults to looking for a global value
if a repo-specific vaue isn't found, existing deployments don't
need to change.
For each test case, initializes a repo state from file if one exists.
@yasunariw yasunariw force-pushed the yasu/support-multiple-repos branch from 9697bed to 233543c Compare May 6, 2022 10:04
@yasunariw yasunariw requested review from Khady and rr0gi May 6, 2022 10:14
@yasunariw yasunariw merged commit 1eab7b5 into master Jun 28, 2022
@yasunariw yasunariw deleted the yasu/support-multiple-repos branch June 28, 2022 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants