Create a JS utility to generate a GitHub comparison URL
See original GitHub issueIf you haven’t already, check out our contributing guidelines for onboarding!
Problem
As part of our new Expensify.cash Deploy & QA process, we’ll need an easy way to view differences between versions. To do so, we’ll generate links to a GitHub comparison.
Why is this important?
This will be an important step for engineers to be able to view changes introduced by a release and track regressions.
Solution
Create a Javascript utility function in expensify-common called generateVersionComparisonURL
that takes in:
- A
repoSlug
- A
tag
(version number) - A
semverLevel
that’s one of `[‘MAJOR’, ‘MINOR’, ‘PATCH’, ‘BUILD’]
And then:
- Fetch the tags of the repo
- Search through the results to find the tag of the previous version of the appropriate
semverLevel
. - Return a URL formatted like:
https://github.com/Expensify/Expensify.cash/compare/<previous_version_tag>...<current_version_tag>
Note: If it doesn’t already exist, this function should be stored in a class called GithubUtils
that takes in an authenticated octokit
client as a parameter to its constructor. This function will be used from the context of Github Actions, where we’ll always have an authenticated client available.
To be considered complete
- Document testing
- Provide automated unit tests.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Whatever the case, a very comprehensive set of automated tests will be the key to success here 👍
@SombreroElGringo Your proposal here looks good. Just a few comments:
You should use the semver library to accomplish this instead of writing your own regexes.
Also, your examples aren’t exactly correct. It should provide a comparison between the highest version of the previous level. Let’s say we have the following tags: 2.2.2-1, 2.2.2, 2.2.1, 2.2.0, 2.1.0-2, 2.1.0-1, 2.1.0, 2.1.2, 2.0.0, 1.1.0 and 1.0.0
generateVersionComparisonURL(“my-repo”, “2.2.2”, “MAJOR”)
should returnhttps://github.com/Expensify/Expensify.cash/compare/1.1.0...2.2.2
not1.0.0...2.2.2
generateVersionComparisonURL(“my-repo”, “2.2.2”, “MINOR”)
should returnhttps://github.com/Expensify/Expensify.cash/compare/2.1.2...2.2.2
not2.1.0
generateVersionComparisonURL(“my-repo”, “2.2.2”, “PATCH”)
should returnhttps://github.com/Expensify/Expensify.cash/compare/2.2.1...2.2.2
generateVersionComparisonURL(“my-repo”, “2.2.2-1”, “BUILD”)
should returnhttps://github.com/Expensify/Expensify.cash/compare/2.2.2...2.2.2-1
not2.1.0-2...2.2.2-1
It’s a bit hard to describe with words, but it should provide a comparison between the version passed as a parameter, and the highest version of the previous
SEMVER_LEVEL
version.In the case of
BUILD
, it will always be a comparison with the previousPATCH
version. Does that make sense?