From 6ebd14759bcfe5834e6bd84260796d2def600f32 Mon Sep 17 00:00:00 2001 From: zhzhang Date: Fri, 8 Nov 2024 17:09:29 +0800 Subject: [PATCH] Fix last commit API with empty repository --- builder/git/gitserver/gitaly/commit.go | 2 +- component/model.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builder/git/gitserver/gitaly/commit.go b/builder/git/gitserver/gitaly/commit.go index 0af84b63..7a68945a 100644 --- a/builder/git/gitserver/gitaly/commit.go +++ b/builder/git/gitserver/gitaly/commit.go @@ -96,7 +96,7 @@ func (c *Client) GetRepoLastCommit(ctx context.Context, req gitserver.GetRepoLas if err != nil { return nil, err } - if resp != nil { + if resp != nil && resp.Commit != nil { commit = types.Commit{ ID: string(resp.Commit.Id), CommitterName: string(resp.Commit.Committer.Name), diff --git a/component/model.go b/component/model.go index ebc8a6c4..8b6721f8 100644 --- a/component/model.go +++ b/component/model.go @@ -484,7 +484,7 @@ func (c *ModelComponent) SDKModelInfo(ctx context.Context, namespace, name, ref, return nil, ErrUnauthorized } - var pipelineTag, libraryTag string + var pipelineTag, libraryTag, sha string var tags []string for _, tag := range model.Repository.Tags { tags = append(tags, tag.Name) @@ -528,10 +528,14 @@ func (c *ModelComponent) SDKModelInfo(ctx context.Context, namespace, name, ref, spaceNames[idx] = s.Name } + if lastCommit != nil { + sha = lastCommit.ID + } + resModel := &types.SDKModelInfo{ ID: model.Repository.Path, Author: model.Repository.User.Username, - Sha: lastCommit.ID, + Sha: sha, CreatedAt: model.Repository.CreatedAt, LastModified: model.Repository.UpdatedAt, Private: model.Repository.Private,