Skip to content

Add CommitFunctions and update config with defaults#768

Merged
Andarist merged 20 commits intochangesets:mainfrom
rohit-gohri:custom-commit-message-script
Mar 27, 2022
Merged

Add CommitFunctions and update config with defaults#768
Andarist merged 20 commits intochangesets:mainfrom
rohit-gohri:custom-commit-message-script

Conversation

@rohit-gohri
Copy link
Contributor

@rohit-gohri rohit-gohri commented Mar 5, 2022

Follow up of #735

Closes #688
Closes #285

Made commit option similar to changelog option but with a default template when "true" is passed (keeping it backward compatible).

This currently doesn't allow disabling commit for one of add/version. Maybe that can be added too if the respective function returns null or doesn't exist?
If one of the functions doesn't exist then we will not commit for that only.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2022

🦋 Changeset detected

Latest commit: 8b855ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@changesets/types Major
@changesets/cli Minor
@changesets/apply-release-plan Major
@changesets/config Major
@changesets/assemble-release-plan Patch
@changesets/changelog-git Patch
@changesets/changelog-github Patch
@changesets/get-dependents-graph Patch
@changesets/get-release-plan Patch
get-workspaces Patch
@changesets/git Patch
@changesets/parse Patch
@changesets/pre Patch
@changesets/read Patch
@changesets/release-utils Patch
@changesets/write Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 5, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8b855ed:

Sandbox Source
Vanilla Configuration

Comment on lines +195 to +202
if (
typeof possibleCommitFunc.getAddLine === "function" &&
typeof possibleCommitFunc.getVersionLine === "function"
) {
getCommitFuncs = possibleCommitFunc;
} else {
throw new Error("Could not resolve commit generation functions");
}
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can start from requiring both to exist - but I wonder if there are people only wanting one of those to kick in 🤔

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 can treat not existing as commit: false for add/version separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added support for partial functions. If only one of it is supplied then commit will be done for that command only

Releases:
${releasesLines}

[skip ci]
Copy link
Member

Choose a reason for hiding this comment

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

What if we would remove this from here and instead add options to this function and only render this based on smth like options.versionSkipCI === true. This way we could "translate" current commit: true to ["@changesets/cli/commit", { versionSkipCI: true }].

This would be quite nice because one could more easily extend the built-in function without having to strip [skip ci] from it if they don't want it. This option would go away in Changesets v3 (if that ever gets published) and would only be supported now to avoid breaking changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great idea, adds back skipCI but as a different option

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 added for both versionSkipCI and addSkipCI, with versionSkipCI as true for the true config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addSkipCI seems like a weird option name now that I have added it, WDYT about just having skipCI and possible values being 'version' | 'add' | boolean?

Copy link
Member

Choose a reason for hiding this comment

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

that works too, I don't mind any of those solutions - I agree that the current names are a little bit weird but since I'd like to remove this in the future anyway... I don't care that much about this :p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to "skipCI": "version" | "add" | boolean as the option.


export default defaultCommitFunctions;

export function getCommitFuncs(
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 actually used anywhere? or just in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used in the add function. I wanted to also use it in apply-release-plan but couldn't figure out how that import would work

Copy link
Member

Choose a reason for hiding this comment

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

I think that it would make sense to introduce a breaking change to the @changesets/apply-release-plan (that would not be a breaking change for the Changesets itself) and just move out the committing logic from it. Based on its return value the "version commit" could be conditionally created within @changesets/cli.

This would make both commit types be performed by a single package - which I think would be a good thing for the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the cli 🙂

@rohit-gohri rohit-gohri requested a review from Andarist March 5, 2022 17:13
@rohit-gohri
Copy link
Contributor Author

All done from my side, the only thing remaining is the name of the skipCI options. See this comment

Comment on lines +91 to +94
while (newTouchedFilesArr.length > 0) {
let file = newTouchedFilesArr.shift();
await git.add(path.relative(cwd, file!), cwd);
}
Copy link
Member

Choose a reason for hiding this comment

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

we don't need to touch this here but it's probably better to construct a single call to git add since stuff like git add file1.js file2.js ... is a totally valid thing to do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The add function in @changesets/git only accepts one path so I'm going to leave this for now.

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist
Copy link
Member

Andarist commented Mar 6, 2022

The PR is almost ready to be shipped, great work! Once all remaining items (mostly nits really) get addressed I will rethink the rollout strategy as we need to consider how this affects the version of the involved packages and how to ensure that this doesn't break any existing consumers.

@LeviticusMB
Copy link

I would love to see this PR merged as soon as possible. What's holding it back?

Really looking forward to being able to turn auto-commit back on without getting that docs(changeset) prefix (which makes no sense when the actual change is just one commit) in the git log.

rohit-gohri and others added 3 commits March 27, 2022 15:14
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist Andarist merged commit c87eba6 into changesets:main Mar 27, 2022
@Andarist
Copy link
Member

What's holding it back?

Lack of the free time of maintainers 😉

@github-actions github-actions bot mentioned this pull request Mar 27, 2022
@Andarist
Copy link
Member

@rohit-gohri thank you very much for your contributions and bearing with me. People like you keep OSS projects afloat 🚀

@LeviticusMB
Copy link

Thanks a lot guys, really awesome! Works as advertised for me.

However, it does look like config/schema.json was not updated to reflect the change?

@Andarist
Copy link
Member

However, it does look like config/schema.json was not updated to reflect the change?

Yeah, we forgot about it - PR with an update would be appreciated.

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.

Ability to set commit to different values in add and version commands. Changesets ignoring the skipCI config key

3 participants