-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
Updated title so that service tests will run, and closing/reopening since CI doesn't seem to be executing |
|
There was a problem hiding this 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
if (license) { | ||
return renderLicenseBadge({ license }) | ||
} else { | ||
return { message: 'not specified' } | ||
} |
There was a problem hiding this comment.
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:
Lines 121 to 123 in fd13db8
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?
There was a problem hiding this comment.
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.
shields/services/github/github-license.service.js
Lines 29 to 37 in dc06b44
static render({ license }) { | |
if (license === 'NOASSERTION') { | |
return { message: 'not identifiable by github' } | |
} else if (license) { | |
return renderLicenseBadge({ license }) | |
} else { | |
return { message: 'not specified' } | |
} | |
} |
There was a problem hiding this comment.
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
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, | ||
}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@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 |
There was a problem hiding this 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
jihulab.com is GitLab's SaaS platform in China, and it is always available. Maybe change the project to |
Either way, doesn't really matter. Just want to target a working/valid combination of server url and project reference |
Overview
This service is for displaying the license of porject in GitLab.
re #7371