Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] Format all git domains, not only github.com #1058

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AndrewChubatiuk
Copy link

What and why?

Enabled formatting of all git remotes, not only github.com to fix datadog serverless plugin tags, while using in projects with repos that are not hosted on github

How?

updated regular expression to replace fix remote urls with any domain name

@AndrewChubatiuk AndrewChubatiuk requested a review from a team as a code owner September 6, 2023 08:13
Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution!

Can you test case(s) for what you changed, and ensure the unit tests are passing?

You can find the existing tests here:

describe('filterAndFormatGithubRemote', () => {
test('git remotes get formatted correctly', async () => {
expect(ciUtils.filterAndFormatGithubRemote('https:/datadog/test.git')).toEqual(
'github.com/datadog/test.git'
)
expect(ciUtils.filterAndFormatGithubRemote('[email protected]:datadog/test.git')).toEqual(
'github.com/datadog/test.git'
)
expect(ciUtils.filterAndFormatGithubRemote('github.com/datadog/test.git')).toEqual('github.com/datadog/test.git')
})
})

@Drarig29 Drarig29 changed the title format all git domains, not only github.com [utils] Format all git domains, not only github.com Sep 6, 2023
@AndrewChubatiuk
Copy link
Author

@Drarig29 done

src/helpers/__tests__/utils.test.ts Outdated Show resolved Hide resolved
@@ -380,6 +380,13 @@ describe('utils', () => {
'github.com/datadog/test.git'
)
expect(ciUtils.filterAndFormatGithubRemote('github.com/datadog/test.git')).toEqual('github.com/datadog/test.git')
expect(ciUtils.filterAndFormatGithubRemote('https://git.some.domain.com:8080/datadog/test.git')).toEqual(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you remove the port? Do you have an example of scenario?

Copy link
Author

@AndrewChubatiuk AndrewChubatiuk Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is being used by serverless-datadog-plugin and colon symbol is a delimiter for key:value pair, had to remove port as well to fix

@Drarig29 Drarig29 requested review from a team September 6, 2023 10:06
@Drarig29 Drarig29 requested a review from a team September 6, 2023 10:41
expect(ciUtils.filterAndFormatGithubRemote('[email protected]:datadog/test.git')).toEqual(
'test.domain.com/datadog/test.git'
)
expect(ciUtils.filterAndFormatGithubRemote('example.domain.com/datadog/test.git')).toEqual('example.domain.com/datadog/test.git')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are formatting all git domains, shouldn't we also change the function name (and jsdocs) to be something different than filterAndFormatGithubRemote? Maybe just filterAndFormatGitRemote? Just a nit, but would be better to keep consistency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it, but this function is exported, so some apps or libs, that depend on it can become broken

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrewChubatiuk good point!

Can you add the original filterAndFormatGithubRemote() function back (with its old implementation and unit tests) and mark it as deprecated like that function?

Thanks in advance, and sorry for the delay!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added filterAndFormatGithubRemote() as alias to filterAndFormatGitRemote() and marked as deprecated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, indeed the unit test did not change, so the new implementation did not change in behavior for the old supported cases.

Copy link
Contributor

@duncanista duncanista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM – left a comment!

@Drarig29
Copy link
Contributor

Drarig29 commented Oct 3, 2023

@AndrewChubatiuk I triggered the CI for your latest commit, and the lint phase fails. Running yarn format should fix it!

Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contribution!

@rpelliard
Copy link
Contributor

Hello @AndrewChubatiuk !

Enabled formatting of all git remotes, not only github.com to fix datadog serverless plugin tags, while using in projects with repos that are not hosted on github

Out of curiosity, are you encountering an issue with the current version ? For context, this normalization for GitHub URLs was introduced to circumvent some limitations around some old tracer versions that don't support the URL scheme in tags, but it shouldn't be necessary in most cases now.

For GitHub repositories, the git@ and https:// repository URLs are predictable / interchangable, so we don't lose any information by stripping the scheme. However, this is not the case for all Git repo hosting providers, so I'd like to make sure we fully understand your issue before merging this change - Thanks !

@AndrewChubatiuk
Copy link
Author

AndrewChubatiuk commented Oct 4, 2023

@rpelliard this function is being used by serverless datadog plugin and it throws exceptions when tries to add labels generated from git: when using non-github git@ origin it fails cause labelname:git@domain:org/repo has more than one colon symbol

@rpelliard
Copy link
Contributor

@AndrewChubatiuk What version of serverless-plugin-datadog, and which language are you using ? The latest one should only bundle versions of the tracing libraries that support the double columns in the tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants