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

Handle commit hash versions #200

Merged
merged 5 commits into from
May 6, 2022

Conversation

guilhermelimak
Copy link
Contributor

@guilhermelimak guilhermelimak commented May 2, 2022

This change re-add support for commit hash versions on both PR diff and title (which I believe were removed after the PR diff changes). They will be merged independently of the target option since the hash doesn't have that information.

Checklist

Closes #199
Closes nearform-actions/github-action-notify-release#189

Prevents a warning message about test/moduleChanges.js having no tests.
This change add support for commit hash versions on both PR diff and title. They will be merged independently of the target option since the hash doesn't have that information.
This will prevent one issue where the PR was not merged and failed silently when there wasn't a target defined
src/action.js Outdated

const packageName = getPackageName(pullRequest.head.ref)

return { [packageName]: { delete: semverCoerce(oldVersion).raw, insert: semverCoerce(newVersion).raw } }
if (semverCoerce(oldVersion) && semverCoerce(newVersion)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's a better way to write this whole section using conditional chaining, let's leverage that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it could be improved, but not by just doing something like this (as it's what I'm assuming you mean:

return {
  [packageName]: {
    delete: semverCoerce(oldVersion)?.raw ?? oldVersion,
    insert: semverCoerce(newVersion)?.raw ?? newVersion
  }
}

I just noticed that semver.coerce sometimes will be a bit too loose when handling some inputs which caused some of the tests to ffail, for instance it will parse cc221b3 as 221.0.0 and such. I'll use a ternary based on semver.valid which will reduce the code repetition.

I'm just fixing the code coverage that was reduced after this change.

src/util.js Outdated
@@ -54,3 +54,7 @@ exports.getPackageName = (branchName) => {

return packageName
}

exports.isCommitHash = function(version) {
return /^[\w]{7}$/.test(version)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't feel very robust. how do we know it will be always 7 chars? we don't!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to this. Do you think that's alright?

@guilhermelimak guilhermelimak requested a review from simoneb May 5, 2022 00:15
@simoneb
Copy link
Collaborator

simoneb commented May 5, 2022

let's merge and cut a patch release please @guilhermelimak

Also add a new test case for a full SHA1 hash.
@guilhermelimak
Copy link
Contributor Author

let's merge and cut a patch release please @guilhermelimak

I don't have write permissions to this repo

@simoneb simoneb merged commit 2d8e405 into fastify:main May 6, 2022
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.

Handle commit hash versions properly
2 participants