Repository: JanDeDobbeleer/oh-my-posh
Pull request #4203 (2023-08-29 21:45:53)

Add AWS CodeCommit upstream for git segment
### Prerequisites

- [x] I have read and understood the [contributing guide][CONTRIBUTING.md].
- [x] The commit message follows the [conventional commits][cc] guidelines.
- [x] Tests for the changes have been added (for bug fixes / features).
- [x] Docs have been added/updated (for bug fixes / features).

### Description

Add AWS CodeCommit upstream for git segment, and fix a typo

### How

Adding a regex to match appropriate URL, and fix a typo

<!---

Tips:

If you're not comfortable with working with Git,
we're working a guide (https://ohmyposh.dev/docs/contributing_git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

### Notes

I did not find a better NF icon, however I would be happy if someone finds one. I'm also getting a space after the icon, I do not know why, help would be appreciated in order to fix this !

[CONTRIBUTING.md]: https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/CONTRIBUTING.md
[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary


kema-dev: Name changed, also fixed the upstream detection regex for codecommit as it was kinda wrong

As you can see in the image, I still get a space after the icon, I don't know why, I think I followed the same principle as other icons, but still, I get one more space.

![image](https://github.com/JanDeDobbeleer/oh-my-posh/assets/54537427/e0cca746-e1ed-453a-895a-3abf3014e8a0)
![image](https://github.com/JanDeDobbeleer/oh-my-posh/assets/54537427/d55c0b4d-c6cc-49af-a730-b1505fca9e88)

I found `nf-md-aws` icon which would be better, but it's code is `\udb83\ude0f` and does not appear to be valid from my formatter :shrug: 

Thanks for creating and maintaining this awesome project though !

Patch:
diff --git a/src/segments/git.go b/src/segments/git.go
index f99b9d36..e38140a7 100644
--- a/src/segments/git.go
+++ b/src/segments/git.go
@@ -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) {
diff --git a/themes/schema.json b/themes/schema.json
index 735ea4ee..d8f41a5d 100644
--- a/themes/schema.json
+++ b/themes/schema.json
@@ -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",
diff --git a/website/docs/segments/git.mdx b/website/docs/segments/git.mdx
index b084d0ed..1db74b0f 100644
--- a/website/docs/segments/git.mdx
+++ b/website/docs/segments/git.mdx
@@ -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 |
 


Test patch:
diff --git a/src/segments/git_test.go b/src/segments/git_test.go
index ecbcf593..e7720067 100644
--- a/src/segments/git_test.go
+++ b/src/segments/git_test.go
@@ -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",