From b94f32271e77246354852d8e6b417d4ea861f052 Mon Sep 17 00:00:00 2001 From: Mike Spiegel Date: Thu, 28 Sep 2023 15:47:58 -0400 Subject: [PATCH] support fetching tags Signed-off-by: Mike Spiegel --- .changeset/itchy-bobcats-fly.md | 5 +++++ packages/backend-common/api-report.md | 6 +++++- packages/backend-common/src/scm/git.test.ts | 4 +++- packages/backend-common/src/scm/git.ts | 9 +++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 .changeset/itchy-bobcats-fly.md diff --git a/.changeset/itchy-bobcats-fly.md b/.changeset/itchy-bobcats-fly.md new file mode 100644 index 0000000000..e91d944478 --- /dev/null +++ b/.changeset/itchy-bobcats-fly.md @@ -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 diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index ab640ccd9b..36cb225a27 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -377,7 +377,11 @@ export class Git { }): Promise; // (undocumented) deleteRemote(options: { dir: string; remote: string }): Promise; - fetch(options: { dir: string; remote?: string }): Promise; + fetch(options: { + dir: string; + remote?: string; + tags?: boolean; + }): Promise; // (undocumented) static fromAuth: (options: { username?: string; diff --git a/packages/backend-common/src/scm/git.test.ts b/packages/backend-common/src/scm/git.test.ts index 629173f96e..5ec960fc53 100644 --- a/packages/backend-common/src/scm/git.test.ts +++ b/packages/backend-common/src/scm/git.test.ts @@ -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', diff --git a/packages/backend-common/src/scm/git.ts b/packages/backend-common/src/scm/git.ts index 234ae57d30..8ccdbeafbd 100644 --- a/packages/backend-common/src/scm/git.ts +++ b/packages/backend-common/src/scm/git.ts @@ -160,8 +160,12 @@ export class Git { } /** https://isomorphic-git.org/docs/en/fetch */ - async fetch(options: { dir: string; remote?: string }): Promise { - const { dir, remote = 'origin' } = options; + async fetch(options: { + dir: string; + remote?: string; + tags?: boolean; + }): Promise { + 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,