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

feat: compact format for if, then and actions #824

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

zolamk
Copy link
Contributor

@zolamk zolamk commented Apr 8, 2023

Description

Introduces a compact form for if, then and actions fields in reviewpad file.

workflows:
  - name: add-label
    if: '$size() <= 30'
    then: '$addLabel("small")'

pipelines:
  - name: renovate-bot
    trigger: $author() == "renovate[bot]"
    stages:
      - actions: $assignAssignees($group("owners"), 1)
        until: $assignees() != []

Related issue

Closes reviewpad/raas-common#103

Type of change

New feature (non-breaking change which adds functionality)

How was this tested?

Manual and Unit tests.

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix/feature works (if applicable) and have tested properly
  • I have ran task check -f and have no issues

Code review and merge strategy (ship/show/ask)

Ask: this pull request requires a code review before merge

@reviewpad reviewpad bot added new-feature Non-breaking change which adds functionality ask Pull request requires a code review before merge large large pull request labels Apr 8, 2023
@reviewpad
Copy link

reviewpad bot commented Apr 8, 2023

AI-Generated Summary: This pull request contains two patches:

  1. The first patch adds support for compact if-then actions in the engine, updating functions and modifying some structs to include the new functionality.
  2. The second patch introduces test coverage that checks the correct handling of multiple compact inline actions and pipelines with compact actions. Several test files are added for input and expected processed output for these test cases.

@reviewpad
Copy link

reviewpad bot commented Apr 8, 2023

Reviewpad Report

‼️ Errors

  • The pull request does not have a linked issue. Please link one. Reviewpad will only assign a reviewer when the pull request is linked to an issue.

@adrianoapmartins
Copy link
Member

/reviewpad summarize

@reviewpad
Copy link

reviewpad bot commented Apr 10, 2023

AI-Generated Summary: This pull request contains two patches that introduce support for compact if-then actions and adds test coverage for them.

The first patch modifies the engine/inline_rules_normalizer.go, engine/lang.go, and engine/loader.go files to add support for compact if-then actions. It primarily involves refactoring some functions, adding helper functions for processing compact rules and actions, and updating the data structures to handle the new format.

The second patch adds new test cases to the engine/loader_test.go and includes the associated YAML files for testing. It tests the handling of files with multiple inline actions and multiple pipelines with compact actions.

Comment on lines 157 to 160
processedActions, err := processCompactActions(rawAction)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this required? From my understanding, actions can either be a string or a list. In the last case, we can iterate and append. Does running processCompactActions is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are gonna have to check the list elements are a string right, instead of repeating that in the loop I figured we could reuse it


actions = append(actions, processedActions...)
}
case nil:
Copy link
Member

Choose a reason for hiding this comment

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

Why nil? What is the use case for nil? In this case shouldn't we return an empty list, i.e. actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's in case the workflow doesn't have any actions but only extra actions associated with the rules

engine/inline_rules_normalizer.go Outdated Show resolved Hide resolved
switch action := nonNormalizedActions.(type) {
case string:
actions = append(actions, action)
case []any:
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be []string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since it's an interface{} type we are processing the type will be []any instead of []string


switch r := rawRule.(type) {
case string:
rule = decodeRule(r)
Copy link
Member

Choose a reason for hiding this comment

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

If my understanding is correct being string can mean the name of a specified rule under rules, which means that this decode is not correct. It works because on line 136 we look for all rules and we will end up with the correct spec.

We don't need to correct this since it's working and we will be addressing this issue later.

Just wanted to create awareness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is just creating a rule structure using the spec as a name and we verify it doesn't exist at a later stage, it was a way of avoiding having duplicate rules if the same spec is repated

engine/inline_rules_normalizer.go Outdated Show resolved Hide resolved
engine/inline_rules_normalizer.go Outdated Show resolved Hide resolved
engine/inline_rules_normalizer.go Outdated Show resolved Hide resolved
engine/inline_rules_normalizer.go Outdated Show resolved Hide resolved
@reviewpad reviewpad bot added the requires-author-attention Pull request requires the author to take action label Apr 12, 2023
@reviewpad
Copy link

reviewpad bot commented Apr 12, 2023

AI-Generated Summary: This pull request includes 3 commits that add support for compact if-then actions, provide test coverage for those actions, and address reviews. The changes involve modifications to the engine/inline_rules_normalizer.go, engine/lang.go, engine/loader.go, and engine/loader_test.go files along with the addition of new test files.

  1. In the first commit, engine/inline_rules_normalizer.go is updated to support compact if-then actions, with functions like processWorkflow, normalizeRules and normalizeActions added or updated.
  2. The second commit adds test coverage for compact if-then actions. Six test files are added and updated in the engine package, and a test case for multiple inline actions is added in engine/loader_test.go.
  3. The third commit includes a refactor to address reviews, with changes mainly in engine/inline_rules_normalizer.go.

@reviewpad reviewpad bot added the waiting-review PR waiting for review label Apr 12, 2023
@ferreiratiago ferreiratiago merged commit 2a22604 into main Apr 13, 2023
@ferreiratiago ferreiratiago deleted the feat/compact-if-then-action branch April 13, 2023 08:43
@reviewpad reviewpad bot removed the waiting-review PR waiting for review label Apr 13, 2023
@reviewpad
Copy link

reviewpad bot commented Apr 13, 2023

📈 Pull Request Metrics

💻 Coding Time: 12 minutes
🛻 Pickup Time: 4 days
👀 Review Time: 19 hours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ask Pull request requires a code review before merge large large pull request new-feature Non-breaking change which adds functionality requires-author-attention Pull request requires the author to take action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants