forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix javascript error when an anonymous user visiting migration page (go-gitea#32144) Make oauth2 code clear. Move oauth2 provider code to their own packages/files (go-gitea#32148) Support repo license (go-gitea#24872) Fix the logic of finding the latest pull review commit ID (go-gitea#32139) Ensure `GetCSRF` doesn't return an empty token (go-gitea#32130) Bump minio-go to latest version (go-gitea#32156)
- Loading branch information
Showing
77 changed files
with
2,006 additions
and
1,023 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package license | ||
|
||
import "strings" | ||
|
||
func GetLicenseNameFromAliases(fnl []string) string { | ||
if len(fnl) == 0 { | ||
return "" | ||
} | ||
|
||
shortestItem := func(list []string) string { | ||
s := list[0] | ||
for _, l := range list[1:] { | ||
if len(l) < len(s) { | ||
s = l | ||
} | ||
} | ||
return s | ||
} | ||
allHasPrefix := func(list []string, s string) bool { | ||
for _, l := range list { | ||
if !strings.HasPrefix(l, s) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
sl := shortestItem(fnl) | ||
slv := strings.Split(sl, "-") | ||
var result string | ||
for i := len(slv); i >= 0; i-- { | ||
result = strings.Join(slv[:i], "-") | ||
if allHasPrefix(fnl, result) { | ||
return result | ||
} | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package license | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetLicenseNameFromAliases(t *testing.T) { | ||
tests := []struct { | ||
target string | ||
inputs []string | ||
}{ | ||
{ | ||
// real case which you can find in license-aliases.json | ||
target: "AGPL-1.0", | ||
inputs: []string{ | ||
"AGPL-1.0-only", | ||
"AGPL-1.0-or-late", | ||
}, | ||
}, | ||
{ | ||
target: "", | ||
inputs: []string{ | ||
"APSL-1.0", | ||
"AGPL-1.0-only", | ||
"AGPL-1.0-or-late", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
result := GetLicenseNameFromAliases(tt.inputs) | ||
assert.Equal(t, result, tt.target) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] # empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.