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

Modularize dependencies for GH payload consumption and Slack message sending #92

Merged
merged 17 commits into from
Dec 24, 2020

Conversation

yasunariw
Copy link
Collaborator

@yasunariw yasunariw commented Dec 18, 2020

Description of the task

Additions

Modularize dependencies for GH payload consumption and Slack message sending

Identified the minimal set of functions that need to be configurable during local vs remote handling, and extracted them to an interface in api.ml. Created local (api_local.ml) and remote (api_remote.ml) implementations of this interface. Turned action.ml into a functor that consumes these implementations. Reused the same functions in action.ml as much as possible in both the production and test environment (see notabot.ml and test.ml). This should extend test coverage and make it easier to triage when something goes wrong in production that worked in testing.

(The name of this branch is misleading. I initially thought the whole Context needs to be differentiated b/w remote and local (see #90), but it in fact only the HTTP calls to Slack and GH needed it.)

Improve documentation

Documented more edge case behaviors in config options.

Bug Fixes

  • Remote config file was being fetched twice per payload
  • Remote commit (from commit comment) was being fetched twice per payload
  • Behavior described in documentation contradicted actual behavior

Other

  • Prefer library functions over DIY solutions for list handling
  • Avoid manually assembling GH URLs when they are available in the payload
  • Authenticate all requests to GH using authorization header instead of query param (will be deprecated)
  • Generally de-spaghettify the code to maintain separation of concerns

How to test

All tests should pass:

make test

References

define local + remote implementations of each
more concise decode_string_pad implementation
The config file now distinguishes between undefined lists and empty
lists. This applies to `allowed_pipelines` in the main config, and
`allow` and `ignore` in the prefix/label rules. Now, an undefined field
is interpreted as a global whitelist, and an empty list is interpreted
as a global blacklist.
Temporarily disable auxiliary commands. Config.t is now mostly redundant
but kept for compatibility with status_rules parsing.
…ests)

Auxiliary cli commands have been reenabled. The tests, as well as
`check_gh_action` and `check_slack_action`, now rely on the
functor-based Action module.
@yasunariw yasunariw force-pushed the yasu/modular-context branch 2 times, most recently from 9422dac to 2b291a1 Compare December 19, 2020 17:02
Secrets are now in their own record field
within the context, so that future secret
additions don’t pollute the outer context
structure. Getters are also defined to
reduce boilerplate exception handling.
@ygrek
Copy link
Contributor

ygrek commented Dec 21, 2020

For fields that expect a list, there's now a clearer semantic distinction between the absence of the field and the presence of an empty list. If the field specifies a whitelist, the former should denote "allow everything" and the latter should denote "ignore everything".

What is the usecase for this distinction?

Copy link
Contributor

@ygrek ygrek left a comment

Choose a reason for hiding this comment

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

bug fixes and improvements sound good, but they should have been done in separate PRs or on master, in current shape this PR is impossible to review at large, too many logic changes, the title "Modularize dependencies for GH payload consumption and Slack message sending" is definitely a lie. Hence the review is cursory.

documentation/config_docs.md Show resolved Hide resolved
documentation/config_docs.md Outdated Show resolved Hide resolved
documentation/config_docs.md Outdated Show resolved Hide resolved
documentation/secret_docs.md Show resolved Hide resolved
lib/common.ml Outdated Show resolved Hide resolved
lib/common.ml Outdated Show resolved Hide resolved
lib/api_remote.ml Show resolved Hide resolved
lib/api_remote.ml Outdated Show resolved Hide resolved
src/notabot.ml Show resolved Hide resolved
@yasunariw
Copy link
Collaborator Author

For fields that expect a list, there's now a clearer semantic distinction between the absence of the field and the presence of an empty list. If the field specifies a whitelist, the former should denote "allow everything" and the latter should denote "ignore everything".

What is the usecase for this distinction?

As a user, if I'm told that allow: [a,b] means allow only a and b, and allow: [a] means allow only a, then wouldn't I expect allow: [] to mean allow nothing, and thus an undefined allow field to mean allow everything?

`Action.process_github_notification` logs all errors raised in its
subroutines.
@yasunariw yasunariw force-pushed the yasu/modular-context branch from 37e7a90 to ab23e00 Compare December 22, 2020 03:32
@ygrek
Copy link
Contributor

ygrek commented Dec 22, 2020

then wouldn't I expect allow: [] to mean allow nothing, and thus an undefined allow field to mean allow everything?

yes, but what is the usecase fpr the rule that allows nothing? it will never match, so there is no usecase for it. I guess the change is alright from consistency pov, but I don't like unnecessary changes (e.g. now you need to ensure this change is applied to deployed configs as well, luckily there is only one currently)

Restore earlier behavior that treated empty list `[]` as “include
everything” for compatibility with existing deployments.
@yasunariw
Copy link
Collaborator Author

yes, but what is the usecase fpr the rule that allows nothing? it will never match, so there is no usecase for it. I guess the change is alright from consistency pov, but I don't like unnecessary changes (e.g. now you need to ensure this change is applied to deployed configs as well, luckily there is only one currently)

That's fair. I've reverted the changes and updated the description. This PR doesn't break existing deployed configs anymore.

@yasunariw yasunariw requested a review from ygrek December 23, 2020 03:20
@yasunariw yasunariw force-pushed the yasu/modular-context branch from 5e0d7af to d21b7e3 Compare December 23, 2020 03:25
Copy link
Contributor

@ygrek ygrek left a comment

Choose a reason for hiding this comment

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

minor comment, lets get this merged

lib/api_local.ml Outdated Show resolved Hide resolved
lib/common.ml Outdated Show resolved Hide resolved
documentation/config_docs.md Outdated Show resolved Hide resolved
@yasunariw yasunariw force-pushed the yasu/modular-context branch from 9e91562 to 66916a5 Compare December 24, 2020 01:39
@yasunariw yasunariw merged commit b7a0fbb into master Dec 24, 2020
@yasunariw yasunariw deleted the yasu/modular-context branch January 4, 2021 07:48
yasunariw added a commit that referenced this pull request Nov 30, 2021
Modularize dependencies for GH payload consumption and Slack message sending
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.

expose interface to streamline remote and local handling logic mock HTTP requests in tests
2 participants