Skip to content

Allow custom templates for messages, branches and PRs#307

Merged
EyalDelarea merged 17 commits intojfrog:devfrom
EyalDelarea:custom_git_formats
Apr 19, 2023
Merged

Allow custom templates for messages, branches and PRs#307
EyalDelarea merged 17 commits intojfrog:devfrom
EyalDelarea:custom_git_formats

Conversation

@EyalDelarea
Copy link
Copy Markdown
Contributor

@EyalDelarea EyalDelarea commented Apr 18, 2023

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • This pull request is on the dev branch.
  • I used gofmt for formatting the code before submitting the pull request.

  • Allow custom formats for Commits, Branches and Pull requests titles.
  • Don't fix indirect dependencies unless there is a specific implementation.
  • Update Frogbot badges

Exmaple:

Given templates:

  branchNameTemplate: "${BRANCH_NAME_HASH} this is custom branch ${IMPACTED_PACKAGE} to ${FIX_VERSION}"

  commitTitleTemplate: "fix(dep) this is my custom commit \n update ${IMPACTED_PACKAGE} to ${FIX_VERSION} "
  
  pullRequestTitleTemplate: "(dependency) new pull request by frogbot,fixing ${IMPACTED_PACKAGE}"

image

@EyalDelarea EyalDelarea added the improvement Automatically generated release notes label Apr 18, 2023
@EyalDelarea EyalDelarea requested a review from eyalbe4 April 18, 2023 17:37
@eyalbe4 eyalbe4 added new feature Automatically generated release notes safe to test Approve running integration tests on a pull request and removed improvement Automatically generated release notes labels Apr 18, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Apr 18, 2023
@github-actions
Copy link
Copy Markdown
Contributor

What is Frogbot?

@eyalbe4 eyalbe4 changed the title Custom git formats Allow custom formats for messages, branches and PRs Apr 19, 2023
Copy link
Copy Markdown
Contributor

@eyalbe4 eyalbe4 left a comment

Choose a reason for hiding this comment

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

I haven't finished reviewing all the code. I'll resume my review soon, but I'm releasingwhat I have so far.

if len(branchName) == 0 {
return nil
}
invalidChars := regexp.MustCompile(BranchNameRegex)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The compile operation is expensive, and it is therefore better to do it once only.

{"dev", "replace:colons:colons", "3.0.0", "frogbot-replace_colons_colons-89e555131b4a70a32fe9d9c44d6ff0fc"},
}

gitManager := utils.GitManager{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line is redundant. Yuo can replace gitManager with utils.GitManager{} in line 212.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't let me run it like that.
And they are all the same so we can create it just once :)

Comment on lines +15 to +26
# [Optional] Custom formats for commits, branches, and PR created by Frogbot.
customFormats:
# Please note, Frogbot will replace the following placeholders
# 1. IMPACTED_PACKAGE
# 2. FIX_VERSION
# Example branchName:"(MyLabel):Vulnerability_fix_IMPACTED_PACKAGE_to_version_FIX_VERSION"

commitTitle: ""

pullRequestTitle: ""

branchName: ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest changing the template to be -

- params:
    # Git parameters
    git:
      # [Mandatory]
      # Name of the git repository to scan
      repoName: repo-name

      # [Mandatory]
      # List of branches to scan
      branches:
        - master

      # [Optional] Template for the branch name generated by Frogbot when creating pull requests with fixes. The template must include ${BRANCH_NAME_HASH}, to ensure that the generated branch name is unique
      # branchNameTemplate: ""

      # [Optional] Template for the commit message generated by Frogbot when creating pull requests with fixes
      # commitMessageTemplate: ""

      # [Optional] Template for the pull request title generated by Frogbot when creating pull requests with fixes. The template can optionally include the following variables:
      # ${IMPACTED_PACKAGE}
      # ${FIX_VERSION} 
      # pullRequestTitleTemplate: ""

Let's add our default values for each variable instead of the existing empty string.

Copy link
Copy Markdown
Contributor

@eyalbe4 eyalbe4 left a comment

Choose a reason for hiding this comment

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

I'm done reviewing everything.

  • I suggest that you first read all of my comments before working o fixing them, beucase some of them are related to each other.
  • While suggesting the changes to the frogbot-config.yml file, I realized that the proper term for for the new config items is actiually not "format" but "template". Let's therefore change all the structs' name to reflect that.
  • We still need to update all the workflow templates with the new variables. Let's do it in a follow-up pull request.
  • I'd be happy to review everything again once done.

@EyalDelarea EyalDelarea temporarily deployed to frogbot April 19, 2023 08:52 — with GitHub Actions Inactive
branches:
- master

# [Optional] Template for the branch name generated by Frogbot when creating pull requests with fixes.The template must include ${BRANCH_NAME_HASH}, to ensure that the generated branch name is unique
Copy link
Copy Markdown
Contributor Author

@EyalDelarea EyalDelarea Apr 19, 2023

Choose a reason for hiding this comment

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

Maybe we should explain the placeholder in the start here?
because they can be used in every template

Suggestion:

Suggested change
# [Optional] Template for the branch name generated by Frogbot when creating pull requests with fixes.The template must include ${BRANCH_NAME_HASH}, to ensure that the generated branch name is unique
# [Optional] Git templates, each template can include the following variables:
# ${IMPACTED_PACKAGE}
# ${FIX_VERSION}
# [Optional] Template for the branch name generated by Frogbot when creating pull requests with fixes.The template must include ${BRANCH_NAME_HASH}, to ensure that the generated branch name is unique
branchNameTemplate: ""
# [Optional] Template for the commit message generated by Frogbot when creating pull requests with fixes
CommitMessageTemplate: ""
# [Optional] Template for the pull request title generated by Frogbot when creating pull requests with fixes.The template can optionally include the following variables:
pullRequestTitleTemplate: ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's think about it after the release.

@EyalDelarea EyalDelarea requested a review from eyalbe4 April 19, 2023 08:56
@github-actions
Copy link
Copy Markdown
Contributor

What is Frogbot?

@EyalDelarea EyalDelarea linked an issue Apr 19, 2023 that may be closed by this pull request
@eyalbe4 eyalbe4 changed the title Allow custom formats for messages, branches and PRs Allow custom templates for messages, branches and PRs Apr 19, 2023
commitMessageTemplate string
// New branch name template
branchNameTemplate string
// New pullRequestTitleTemplate title template
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// New pullRequestTitleTemplate title template
-->
// New pull request title template

Comment on lines +31 to +35
BranchInvalidChars = "branch name cannot contain the following chars ~, ^, :, ?, *, [, ], @, {, }"
BranchInvalidPrefix = "branch name cannot start with '-' "
BranchCharsMaxLength = 255
BranchInvalidLength = "branch name length exceeded " + string(rune(BranchCharsMaxLength)) + " chars"
InvalidBranchTemplate = "branch template must contain " + BranchHashPlaceHolder + " placeholder "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The above consts can be made private,

if len(branchName) == 0 {
return nil
}
invalidChars := regexp.MustCompile(branchNameRegex)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As I suggest before, MustCompile should berun only once. You can therefore have a private const that is initialized with regexp.MustCompile(branchNameRegex).

return
}

func TestIsValidBranchName(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TestIsValidBranchName --> TestValidatedBranchName
(the test name should match the function name, which is validateBranchName).

return candidateMajorVersion != currentMajorVersion
}

func ValidateBranchName(branchName string) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function can be made private,

branches:
- master

# [Optional] Template for the branch name generated by Frogbot when creating pull requests with fixes.The template must include ${BRANCH_NAME_HASH}, to ensure that the generated branch name is unique
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's think about it after the release.

- master

# [Optional] Template for the branch name generated by Frogbot when creating pull requests with fixes.The template must include ${BRANCH_NAME_HASH}, to ensure that the generated branch name is unique
branchNameTemplate: ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's put this line as a comment (with a # prefix) and set the default value as the value.
The same goes for the two templates below.

@EyalDelarea EyalDelarea temporarily deployed to frogbot April 19, 2023 12:50 — with GitHub Actions Inactive
@github-actions
Copy link
Copy Markdown
Contributor

What is Frogbot?

@EyalDelarea EyalDelarea merged commit e0ab27d into jfrog:dev Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to configure the commit messages style

2 participants