-
Notifications
You must be signed in to change notification settings - Fork 492
refactor!: normalize configuration across classes #763
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #763 +/- ##
==========================================
+ Coverage 88.92% 89.22% +0.30%
==========================================
Files 59 60 +1
Lines 7690 7753 +63
Branches 675 728 +53
==========================================
+ Hits 6838 6918 +80
+ Misses 851 834 -17
Partials 1 1
Continue to review full report at Codecov.
|
|
found some holes in |
bcoe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple initial questions, will give a more thorough review later today.
In general I really like the approach, it seems like you've gone the route that: rather than pulling more functionality into ReleasePR, so that it's available when creating a release, you now have an instance of a ReleasePR in a GithubRelease?
This seems really smart to me.
| }) | ||
| .option('default-branch', { | ||
| describe: '', | ||
| describe: 'The branch to open release PRs against and tag releases on', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
| versionFile, | ||
| }); | ||
|
|
||
| return new GitHubRelease({github, releasePR, ...remaining}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach, this ends up meaning that the GitHub release can use any releaser specific methods on releasePR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHubRelease already relies on a ReleasePR instance for to perform it's one job (run) - this change is simple removing the knowledge of how to construct it (and thus also removing any duplicate constructor options) and centralizing it in case other future classes (aka aggregate) need one too. Same pattern as pulling out the building of a GitHub instance because that was already being duplicated (by ReleasePR)
src/index.ts
Outdated
| repo: string; | ||
| } | ||
|
|
||
| // Used by GitHubRelease and ReleasePR Ctor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might spell this out constructor, had to Google the shorthand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do. I had to look it up too not that long ago (finally got tired of seeing it everywhere on SO and not really knowing what it mean). I come from python where init is both short and accurate :-)
| const cc = new ConventionalCommits({ | ||
| commits: commits, | ||
| githubRepoUrl: this.repoUrl, | ||
| owner: this.gh.owner, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just standardizing on splitting own owner and repo in more places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea is to consider repoUrl as denormalized shorthand user input for factory.ts and that it should be normalized only once into {owner, repo} and everything else inside the release-please codebase should rely on those directly rather than either carry around this copy of the short hand that everyone then has to convert. It would be a different story if different actors converted it differently but they all just use parse-github-repo-url to get the owner and repo.
src/releasers/node.ts
Outdated
| } | ||
| return { | ||
| name: this.packageName, | ||
| refSafeName: () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding refSafeName properly, it codifies dropping the @pkg/ prefix from a branch name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but I think I'll change it to getComponent() per a discussion with @chingor13
In this refactor I tried to steer away as much as possible from functionality refactoring or re-naming. The one exception is that darned quagmire of (packagePrefix vs packageName) x (set via configuration vs releaser knows how to get it): there was a nasty tangle of responsibility leaking that I needed to cleanup to normalize the configuration. Maybe
PackageName.refSafeName()is better namedPackageName.getComponent()- that's more inline with the domain vocabulary we've chosen and being safe to use as/in a git ref is just a requirement of a component rather than the name
2cb9f20 to
e19dc1c
Compare
bcoe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question for you, was scratching my head trying to figure out where remaining is assigned (maybe I'm misunderstanding something magic about spread operators).
It also jumped out at me that perhaps label should only be a string during parsing.
src/bin/release-please.ts
Outdated
| choices: getReleaserTypes(), | ||
| }; | ||
| if (defaultType) { | ||
| relTypeOptions['default'] = defaultType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: relTypeOptions.default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ug, brain frazzle (when I get tired the python slips back in)
| changelogSections, | ||
| lastPackageVersion, | ||
| versionFile, | ||
| ...remaining |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to be missing where remaining is defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't hyperlink to the exact location but search for the string "Rest in Object Destructuring " in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
in this case remaining is whatever is left of the options parameter that wasn't pulled out in the destructuring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat, haven't used that pattern.
src/release-pr.ts
Outdated
| this.bumpMinorPreMajor = options.bumpMinorPreMajor || false; | ||
| this.defaultBranch = options.defaultBranch; | ||
| this.fork = !!options.fork; | ||
| this.labels = options.label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit weird that label starts as a string, that's split, and then we pass it around as an array of strings to the GitHub instance.
We could coerce labels into an array in the CLI, using .coerce and in the GitHub action, and perhaps make labels an array from the factory onwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. Do you want me to do that in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm doing it in this PR - and it's leading to another GitHubRelease option culling: that class doesn't need this.labels now that it has a releasePR instance. I hadn't looked closely but it turns out ReleasePR.labels is supposed be the same as GitHubRelease.labels. Back before GitHubRelease had a releaser instance that duplication was necessary, but not anymore
|
|
||
| export class Node extends ReleasePR { | ||
| async getOpenPROptions( | ||
| private pkgJsonContents?: GitHubFileContents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just an optimization so that we only load once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah - the original _run code loads the contents at the beginning only once and passes it to the PackageJson Updater as well as sets self.packageName - but now that I've tried to make getPackageName() available potentially prior to any "run" I thought I'd cache it here. But maybe potential caching bugs aren't worth the small cost of an extra API call or two?
| const repoUrls = [ | ||
| `${owner}/${repo}`, | ||
| `${owner}/${repo}`, | ||
| `https://github.com/${owner}/${repo}.git`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate these tests, and that we're so forgiving with the input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, I have the same input listed twice. I was just trying to copy some examples from https://github.com/repo-utils/parse-github-repo-url#features
| octokitAPIs, | ||
| }); | ||
|
|
||
| const labels = getLabels(label); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like this approach.
This is a first take at normalizing the configuration options used to construct GitHub, ReleasePR, and GitHubRelease instances as well as higher level configuration used by the factory entrypoints to build them. The principal motivation is to bring the code more inline with IoC/DI patterns (https://stackoverflow.com/a/3140/13802304) refactor!: interfaces for constructor options moved to src/index.ts and signficantly reorganized refactor!: GitHub constructor: GitHubConstructorOptions refactor!: GitHubRelease constructor: GitHubReleaseConstructorOptions refactor!: ReleasePR constructor: ReleasePRConstructorOptions refactor!: ReleasePR package name handling refactored - lookupPackageName removed in favor of getPackageName refactor!: ConventionalCommits constructor takes owner and repo instead of just repoUrl refactor!: remove GitHubRelease.labels in favor of ReleasePR.labels
2220605 to
9a79a64
Compare
This is a first take at normalizing the configuration options used to
construct GitHub, ReleasePR, and GitHubRelease instances as well as
higher level configuration used by the factory entrypoints to build
them. The principal motivation is to bring the code more inline with
IoC/DI patterns (https://stackoverflow.com/a/3140/13802304)
refactor!: interfaces for constructor options moved to src/index.ts
and signficantly reorganized
refactor!: GitHub constructor: GitHubConstructorOptions
refactor!: GitHubRelease constructor: GitHubReleaseConstructorOptions
refactor!: ReleasePR constructor: ReleasePRConstructorOptions
refactor!: ReleasePR package name handling refactored -
lookupPackageName removed in favor of getPackageName
refactor!: ConventionalCommits constructor takes owner and repo instead
of just repoUrl
refactor!: remove GitHubRelease.labels in favor of ReleasePR.labels