Skip to content

Commit

Permalink
feat: Allow GetRevisionMetadata to use truncated sha revision (#5265)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Veitas <[email protected]>
  • Loading branch information
mveitas authored Jan 20, 2021
1 parent 54716ac commit 41fb0ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ func (s *Service) GetAppDetails(ctx context.Context, q *apiclient.RepoServerAppD
}

func (s *Service) GetRevisionMetadata(ctx context.Context, q *apiclient.RepoServerRevisionMetadataRequest) (*v1alpha1.RevisionMetadata, error) {
if !git.IsCommitSHA(q.Revision) {
if !(git.IsCommitSHA(q.Revision) || git.IsTruncatedCommitSHA(q.Revision)) {
return nil, fmt.Errorf("revision %s must be resolved", q.Revision)
}
metadata, err := s.cache.GetRevisionMetadata(q.Repo.Repo, q.Revision)
Expand Down
18 changes: 16 additions & 2 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,20 @@ func TestGetRevisionMetadata(t *testing.T) {
assert.EqualValues(t, []string{"tag1", "tag2"}, res.Tags)
assert.NotEmpty(t, res.SignatureInfo)

// Check for truncated revision value
res, err = service.GetRevisionMetadata(context.Background(), &apiclient.RepoServerRevisionMetadataRequest{
Repo: &argoappv1.Repository{},
Revision: "c0b400f",
CheckSignature: true,
})

assert.NoError(t, err)
assert.Equal(t, strings.Repeat("a", 61)+"...", res.Message)
assert.Equal(t, now, res.Date.Time)
assert.Equal(t, "author", res.Author)
assert.EqualValues(t, []string{"tag1", "tag2"}, res.Tags)
assert.NotEmpty(t, res.SignatureInfo)

// Cache hit - signature info should not be in result
res, err = service.GetRevisionMetadata(context.Background(), &apiclient.RepoServerRevisionMetadataRequest{
Repo: &argoappv1.Repository{},
Expand All @@ -1010,7 +1024,7 @@ func TestGetRevisionMetadata(t *testing.T) {
// Enforce cache miss - signature info should not be in result
res, err = service.GetRevisionMetadata(context.Background(), &apiclient.RepoServerRevisionMetadataRequest{
Repo: &argoappv1.Repository{},
Revision: "c0b400fc458875d925171398f9ba9eabd5529924",
Revision: "da52afd3b2df1ec49470603d8bbb46954dab1091",
CheckSignature: false,
})
assert.NoError(t, err)
Expand All @@ -1019,7 +1033,7 @@ func TestGetRevisionMetadata(t *testing.T) {
// Cache hit on previous entry that did not have signature info
res, err = service.GetRevisionMetadata(context.Background(), &apiclient.RepoServerRevisionMetadataRequest{
Repo: &argoappv1.Repository{},
Revision: "c0b400fc458875d925171398f9ba9eabd5529924",
Revision: "da52afd3b2df1ec49470603d8bbb46954dab1091",
CheckSignature: true,
})
assert.NoError(t, err)
Expand Down

0 comments on commit 41fb0ac

Please sign in to comment.