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

Add [gitlablicense] services #8024

Merged
merged 6 commits into from
Jun 12, 2022
Merged

Conversation

sunny0826
Copy link
Contributor

Overview

This service is for displaying the license of porject in GitLab.

re #7371

@calebcartwright calebcartwright added the service-badge Accepted and actionable changes, features, and bugs label May 31, 2022
@calebcartwright calebcartwright changed the title Add gitlab license services Add [gitlablicense] services May 31, 2022
@calebcartwright
Copy link
Member

Updated title so that service tests will run, and closing/reopening since CI doesn't seem to be executing

@shields-ci
Copy link

shields-ci commented May 31, 2022

Messages
📖 ✨ Thanks for your contribution to Shields, @sunny0826!

Generated by 🚫 dangerJS against bb0c8a1

Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

Thank you! Few minor things inline but looking great so far

services/gitlab/gitlab-license.service.js Outdated Show resolved Hide resolved
Comment on lines +46 to +50
if (license) {
return renderLicenseBadge({ license })
} else {
return { message: 'not specified' }
}
Copy link
Member

Choose a reason for hiding this comment

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

The renderLicenseBadge helper actually handles cases when there's no license provided:

if (licenses.length === 0) {
return { message: 'missing', color: 'red' }
}

and the benefit of utilizing that is both simplicity in code and also consistency across our badges.

Did you structure this with different behavior deliberately or was it just simply a case of not knowing the helper handled that, and if it's the former, would you mind explaining your thought process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refer to the Github licence for this part.

static render({ license }) {
if (license === 'NOASSERTION') {
return { message: 'not identifiable by github' }
} else if (license) {
return renderLicenseBadge({ license })
} else {
return { message: 'not specified' }
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, thanks for sharing. I'd be curious to know what other maintainers think, if there's more backstory on why GitHub is handled this way. Given the goals of the project I'd be hesitant to introduce this another case of inconsistent behavior in the no license scenario, unless there's good reason

services/gitlab/gitlab-license.service.js Show resolved Hide resolved
Comment on lines +38 to +57
t.create('Mocking License')
.get('/group/project.json')
.intercept(nock =>
nock('https://gitlab.com')
.get('/api/v4/projects/group%2Fproject?license=1')
.reply(200, {
license: {
key: 'apache-2.0',
name: 'Apache License 2.0',
nickname: '',
html_url: 'http://choosealicense.com/licenses/apache-2.0/',
source_url: '',
},
})
)
.expectBadge({
label: 'license',
message: 'Apache License 2.0',
color: unknownLicenseColor,
})
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we necessarily have to remove this test (in part because I realize it bears similarity to the corresponding github tests), but did want to note that it's not necessary for purposes of service/integration tests.

The license renderer is already extensively tested so we're typically content not trying to retest that logic in service tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I wrote this test more to show the data structure of licence, so that the developer can understand what fields are in the structure directly through this test case, without having to actually call it.

Copy link
Member

Choose a reason for hiding this comment

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

Understood, and again don't feel like you need to change anything, but my point is that we don't really do that especially not with our service tests. The schema we define in the service class that is used for validating response objects from the upstream APIs is how we typically "document" the structure and relevant fields, along with trying to include links to the upstream documentation.

Compared to other types of tests our service tests are slow and expensive and we typically use them to provide validation against the upstream services we integrate with/to catch when vendors/platforms make breaking changes to their APIs. They can be used to test/do other things, it's just that we typically try to refrain from doing so because of the associated drawbacks.

This is just an fyi/food for thought in case you decide you'd like to work on other badges in the future, GitLab or otherwise

@sunny0826
Copy link
Contributor Author

@calebcartwright Can this PR be merged, and I hope to contribute a series of badges about GitLab afterwards.

@calebcartwright
Copy link
Member

@calebcartwright Can this PR be merged, and I hope to contribute a series of badges about GitLab afterwards.

https://github.com/badges/shields/pull/8024/files#r890712363 was still pending in my mind. However, I think my fellow maintainers have been quite busy of late and haven't had much bandwidth for Shields, and I suspect that will continue to be the case for the foreseeable future.

I'll do one more pass and proceed with merging if nothing else jumps out

Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

Will go ahead and approve but also note a few things that may/will require follow up:

  • The behavior discussed in Add [gitlablicense] services #8024 (comment) should be revisited, at least to confirm this is desired. I don't have any concerns with proceeding though as we should be able to change this semi-error path later on.
  • We strive to have our sample parameters used in defaults be valid/usable, so if a user utilizes them to test the badge will work. However, the example listing with the custom server url (https://jihulab.com) ends up being invalid because it is reusing the shared/common props, and there is no gitlab-org/gitlab-foss project on that server. We should update the server url or use explicit project args for the existing server in order for that example to be valid

@repo-ranger repo-ranger bot merged commit 781aedc into badges:master Jun 12, 2022
@sunny0826
Copy link
Contributor Author

Will go ahead and approve but also note a few things that may/will require follow up:

  • The behavior discussed in #8024 (comment) should be revisited, at least to confirm this is desired. I don't have any concerns with proceeding though as we should be able to change this semi-error path later on.
  • We strive to have our sample parameters used in defaults be valid/usable, so if a user utilizes them to test the badge will work. However, the example listing with the custom server url (https://jihulab.com) ends up being invalid because it is reusing the shared/common props, and there is no gitlab-org/gitlab-foss project on that server. We should update the server url or use explicit project args for the existing server in order for that example to be valid

jihulab.com is GitLab's SaaS platform in China, and it is always available. Maybe change the project to gitlab-cn/gitlab, which is public and is used to collaborate with GitLab.com.

@sunny0826 sunny0826 deleted the feat/gitlab-license branch June 12, 2022 01:39
@calebcartwright
Copy link
Member

Maybe change the project to gitlab-cn/gitlab, which is public and is used to collaborate with GitLab.com.

Either way, doesn't really matter. Just want to target a working/valid combination of server url and project reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants