Merge pull request #20244 from mspiegel31/update-git-client

feat: support fetching tags in git client
This commit is contained in:
Ben Lambert
2023-10-03 11:00:25 +02:00
committed by GitHub
4 changed files with 20 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Added the ability to fetch git tags through the `Git` class. This is useful for scaffolder actions that want to take action based on tag versions in a cloned repository
+5 -1
View File
@@ -377,7 +377,11 @@ export class Git {
}): Promise<string | undefined>;
// (undocumented)
deleteRemote(options: { dir: string; remote: string }): Promise<void>;
fetch(options: { dir: string; remote?: string }): Promise<void>;
fetch(options: {
dir: string;
remote?: string;
tags?: boolean;
}): Promise<void>;
// (undocumented)
static fromAuth: (options: {
username?: string;
+3 -1
View File
@@ -264,13 +264,14 @@ describe('Git', () => {
};
const git = Git.fromAuth(auth);
await git.fetch({ remote, dir });
await git.fetch({ remote, dir, tags: true });
expect(isomorphic.fetch).toHaveBeenCalledWith({
fs,
http,
remote,
dir,
tags: true,
onProgress: expect.any(Function),
headers: {
'user-agent': 'git/@isomorphic-git',
@@ -294,6 +295,7 @@ describe('Git', () => {
http,
remote,
dir,
tags: false,
onProgress: expect.any(Function),
headers: {
Authorization: 'Bearer test',
+7 -2
View File
@@ -160,8 +160,12 @@ export class Git {
}
/** https://isomorphic-git.org/docs/en/fetch */
async fetch(options: { dir: string; remote?: string }): Promise<void> {
const { dir, remote = 'origin' } = options;
async fetch(options: {
dir: string;
remote?: string;
tags?: boolean;
}): Promise<void> {
const { dir, remote = 'origin', tags = false } = options;
this.config.logger?.info(
`Fetching remote=${remote} for repository {dir=${dir}}`,
);
@@ -172,6 +176,7 @@ export class Git {
http,
dir,
remote,
tags,
onProgress: this.onProgressHandler(),
headers: this.headers,
onAuth: this.onAuth,