-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from emulsify-ds/36-default-system-install-pi…
…n-latest feat(36): adding latest tag when available
- Loading branch information
Showing
4 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import getRepositoryLatestTag from './getRepositoryLatestTag'; | ||
import git from 'simple-git'; | ||
|
||
const gitTagsMock = git().tags as jest.Mock; | ||
|
||
describe('getLatestRepositoryTag', () => { | ||
beforeEach(() => { | ||
gitTagsMock.mockClear(); | ||
}); | ||
it('Can get latest tag from repository url', async () => { | ||
expect.assertions(1); | ||
gitTagsMock.mockReturnValueOnce({ latest: '1.5.0' }); | ||
const latest = await getRepositoryLatestTag( | ||
'[email protected]:emulsify-ds/compound.git' | ||
); | ||
expect(latest).toBe('1.5.0'); | ||
}); | ||
|
||
it('Can return empty if no latest tag is found', async () => { | ||
expect.assertions(1); | ||
const latest = await getRepositoryLatestTag( | ||
'[email protected]:emulsify-ds/compoun.git' | ||
); | ||
expect(latest).toBe(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import simpleGit from 'simple-git'; | ||
|
||
const git = simpleGit(); | ||
|
||
/** | ||
* Helper function to get the latest tag for a given repository url. | ||
* | ||
* @param url git url to use | ||
* @returns string of the latest tag or undefined. | ||
*/ | ||
export default async function getRepositoryLatestTag( | ||
url: string | ||
): Promise<string | undefined> { | ||
const repositoryTags = await git | ||
.init() | ||
.addRemote('origin', url) | ||
.fetch() | ||
.tags(); | ||
return repositoryTags.latest; | ||
} |