Skip to content

Commit 28cff7c

Browse files
authored
Merge branch 'main' into lunny/fix_review_comment_x_ref
2 parents f51b881 + fc4cb07 commit 28cff7c

File tree

45 files changed

+99
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+99
-74
lines changed

modules/actions/artifacts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func IsArtifactV4(art *actions_model.ActionArtifact) bool {
2020

2121
func DownloadArtifactV4ServeDirectOnly(ctx *context.Base, art *actions_model.ActionArtifact) (bool, error) {
2222
if setting.Actions.ArtifactStorage.ServeDirect() {
23-
u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, nil)
23+
u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, ctx.Req.Method, nil)
2424
if u != nil && err == nil {
2525
ctx.Redirect(u.String(), http.StatusFound)
2626
return true, nil

modules/git/commit_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type CommitInfo struct {
1515
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
1616
fullPath := path.Join(treePathDir, entry.Name())
1717
submodule, err := commit.GetSubModule(fullPath)
18-
if err != nil {
18+
if submodule == nil || err != nil {
1919
return nil, err
2020
}
2121
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil

modules/git/commit_info_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
)
1314

1415
const (
@@ -120,6 +121,16 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
120121
defer clonedRepo1.Close()
121122

122123
testGetCommitsInfo(t, clonedRepo1)
124+
125+
t.Run("NonExistingSubmoduleAsNil", func(t *testing.T) {
126+
commit, err := bareRepo1.GetCommit("HEAD")
127+
require.NoError(t, err)
128+
tree, err := commit.GetTreeEntryByPath("file1.txt")
129+
require.NoError(t, err)
130+
cisf, err := getCommitInfoSubmoduleFile("/any/repo-link", tree, commit, "")
131+
require.NoError(t, err)
132+
assert.Nil(t, cisf)
133+
})
123134
}
124135

125136
func BenchmarkEntries_GetCommitsInfo(b *testing.B) {

modules/git/commit_submodule.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error) {
3535
return c.submoduleCache, nil
3636
}
3737

38-
// GetSubModule get the submodule according entry name
38+
// GetSubModule gets the submodule by the entry name.
39+
// It returns "nil, nil" if the submodule does not exist, caller should always remember to check the "nil"
3940
func (c *Commit) GetSubModule(entryName string) (*SubModule, error) {
4041
modules, err := c.GetSubModules()
4142
if err != nil {

modules/packages/content_store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (s *ContentStore) ShouldServeDirect() bool {
3636
return setting.Packages.Storage.ServeDirect()
3737
}
3838

39-
func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename string, reqParams url.Values) (*url.URL, error) {
40-
return s.store.URL(KeyToRelativePath(key), filename, reqParams)
39+
func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename, method string, reqParams url.Values) (*url.URL, error) {
40+
return s.store.URL(KeyToRelativePath(key), filename, method, reqParams)
4141
}
4242

4343
// FIXME: Workaround to be removed in v1.20

modules/storage/azureblob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (a *AzureBlobStorage) Delete(path string) error {
247247
}
248248

249249
// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
250-
func (a *AzureBlobStorage) URL(path, name string, reqParams url.Values) (*url.URL, error) {
250+
func (a *AzureBlobStorage) URL(path, name, _ string, reqParams url.Values) (*url.URL, error) {
251251
blobClient := a.getBlobClient(path)
252252

253253
startTime := time.Now()

modules/storage/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (s discardStorage) Delete(_ string) error {
3030
return fmt.Errorf("%s", s)
3131
}
3232

33-
func (s discardStorage) URL(_, _ string, _ url.Values) (*url.URL, error) {
33+
func (s discardStorage) URL(_, _, _ string, _ url.Values) (*url.URL, error) {
3434
return nil, fmt.Errorf("%s", s)
3535
}
3636

modules/storage/helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Test_discardStorage(t *testing.T) {
3737
assert.Error(t, err, string(tt))
3838
}
3939
{
40-
got, err := tt.URL("path", "name", nil)
40+
got, err := tt.URL("path", "name", "GET", nil)
4141
assert.Nil(t, got)
4242
assert.Errorf(t, err, string(tt))
4343
}

modules/storage/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (l *LocalStorage) Delete(path string) error {
114114
}
115115

116116
// URL gets the redirect URL to a file
117-
func (l *LocalStorage) URL(path, name string, reqParams url.Values) (*url.URL, error) {
117+
func (l *LocalStorage) URL(path, name, _ string, reqParams url.Values) (*url.URL, error) {
118118
return nil, ErrURLNotSupported
119119
}
120120

modules/storage/minio.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,20 @@ func (m *MinioStorage) Delete(path string) error {
279279
}
280280

281281
// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
282-
func (m *MinioStorage) URL(path, name string, serveDirectReqParams url.Values) (*url.URL, error) {
282+
func (m *MinioStorage) URL(path, name, method string, serveDirectReqParams url.Values) (*url.URL, error) {
283283
// copy serveDirectReqParams
284284
reqParams, err := url.ParseQuery(serveDirectReqParams.Encode())
285285
if err != nil {
286286
return nil, err
287287
}
288288
// TODO it may be good to embed images with 'inline' like ServeData does, but we don't want to have to read the file, do we?
289289
reqParams.Set("response-content-disposition", "attachment; filename=\""+quoteEscaper.Replace(name)+"\"")
290-
u, err := m.client.PresignedGetObject(m.ctx, m.bucket, m.buildMinioPath(path), 5*time.Minute, reqParams)
290+
expires := 5 * time.Minute
291+
if method == http.MethodHead {
292+
u, err := m.client.PresignedHeadObject(m.ctx, m.bucket, m.buildMinioPath(path), expires, reqParams)
293+
return u, convertMinioErr(err)
294+
}
295+
u, err := m.client.PresignedGetObject(m.ctx, m.bucket, m.buildMinioPath(path), expires, reqParams)
291296
return u, convertMinioErr(err)
292297
}
293298

0 commit comments

Comments
 (0)