feat(git): add aws codecommit upstream

This commit is contained in:
kema 2023-08-30 21:08:54 +02:00 committed by GitHub
parent 7cf63eead5
commit dba8b2f7ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions
src/segments
themes
website/docs/segments

View file

@ -93,12 +93,14 @@ const (
MergeIcon properties.Property = "merge_icon"
// UpstreamIcons allows to add custom upstream icons
UpstreamIcons properties.Property = "upstream_icons"
// GithubIcon shows when upstream is github
// GithubIcon shows when upstream is github
GithubIcon properties.Property = "github_icon"
// BitbucketIcon shows when upstream is bitbucket
BitbucketIcon properties.Property = "bitbucket_icon"
// AzureDevOpsIcon shows when upstream is azure devops
AzureDevOpsIcon properties.Property = "azure_devops_icon"
// CodeCommit shows when upstream is aws codecommit
CodeCommit properties.Property = "codecommit_icon"
// GitlabIcon shows when upstream is gitlab
GitlabIcon properties.Property = "gitlab_icon"
// GitIcon shows when the upstream can't be identified
@ -425,6 +427,11 @@ func (g *Git) cleanUpstreamURL(url string) string {
path = strings.TrimSuffix(path, ".git")
return fmt.Sprintf("https://%s/%s", match["URL"], path)
}
// codecommit::region-identifier-id://repo-name
match = regex.FindNamedRegexMatch(`codecommit::(?P<URL>[a-z0-9-]+)://(?P<PATH>[\w\.@\:/\-~]+)`, url)
if len(match) != 0 {
return fmt.Sprintf("https://%s.console.aws.amazon.com/codesuite/codecommit/repositories/%s/browse?region=%s", match["URL"], match["PATH"], match["URL"])
}
// user@host.xz:/path/to/repo.git
match = regex.FindNamedRegexMatch(`.*@(?P<URL>.*):(?P<PATH>.*).git`, url)
if len(match) == 0 {
@ -457,6 +464,7 @@ func (g *Git) getUpstreamIcon() string {
"bitbucket": {BitbucketIcon, "\uF171 "},
"dev.azure.com": {AzureDevOpsIcon, "\uEBE8 "},
"visualstudio.com": {AzureDevOpsIcon, "\uEBE8 "},
"codecommit": {CodeCommit, "\uF270 "},
}
for key, value := range defaults {
if strings.Contains(g.UpstreamURL, key) {

View file

@ -630,6 +630,7 @@ func TestGitUpstream(t *testing.T) {
{Case: "Bitbucket", Expected: "BB", Upstream: "bitbucket.org/test"},
{Case: "Azure DevOps", Expected: "AD", Upstream: "dev.azure.com/test"},
{Case: "Azure DevOps Dos", Expected: "AD", Upstream: "test.visualstudio.com"},
{Case: "CodeCommit", Expected: "AC", Upstream: "codecommit::eu-west-1://test-repository"},
{Case: "Gitstash", Expected: "G", Upstream: "gitstash.com/test"},
{Case: "My custom server", Expected: "CU", Upstream: "mycustom.server/test"},
}
@ -644,6 +645,7 @@ func TestGitUpstream(t *testing.T) {
GitlabIcon: "GL",
BitbucketIcon: "BB",
AzureDevOpsIcon: "AD",
CodeCommit: "AC",
GitIcon: "G",
UpstreamIcons: map[string]string{
"mycustom.server": "CU",

View file

@ -982,6 +982,12 @@
"description": "Icon/text to display when the upstream is Azure DevOps",
"default": "\uEBE8"
},
"codecommit_icon": {
"type": "string",
"title": "CodeCommit Icon",
"description": "Icon/text to display when the upstream is CodeCommit",
"default": "\uF270"
},
"git_icon": {
"type": "string",
"title": "Git Icon",

View file

@ -116,6 +116,7 @@ You can set the following properties to `true` to enable fetching additional inf
| `gitlab_icon` | `string` | icon/text to display when the upstream is Gitlab - defaults to `\uF296 ` |
| `bitbucket_icon` | `string` | icon/text to display when the upstream is Bitbucket - defaults to `\uF171 ` |
| `azure_devops_icon` | `string` | icon/text to display when the upstream is Azure DevOps - defaults to `\uEBE8 ` |
| `codecommit_icon` | `string` | icon/text to display when the upstream is Azure DevOps - defaults to `\uF270 ` |
| `git_icon` | `string` | icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB ` |
| `upstream_icons` | `map[string]string` | a key, value map representing the remote URL (or a part of that URL) and icon to use in case the upstream URL contains the key. These get precedence over the standard icons |