-
Notifications
You must be signed in to change notification settings - Fork 145
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
feat: add support for GitLab repositories #84
Conversation
The repoType is a choice between github and gitlab (default is github) and repoHost is a string which default to either 'https://github.com' or 'https://gitlab.com' depending on the answer given for 'repoType'
Codecov Report
@@ Coverage Diff @@
## master #84 +/- ##
==========================================
+ Coverage 52.79% 53.54% +0.75%
==========================================
Files 18 19 +1
Lines 322 409 +87
Branches 44 66 +22
==========================================
+ Hits 170 219 +49
- Misses 135 161 +26
- Partials 17 29 +12
Continue to review full report at Codecov.
|
add methods to get config options, get users and get contributors add tests for most of the implemented code
fix both files to include 'repoType' and 'repoHost' in their options stub
…new repo api main changes include using methods that were fixed for github before, or passing extra parameters from the options object
…code all code that interacts with repositories is now under the repo folder, and therefore is deleted here
this allows for future call of these functions recursively if necessary
… method gitlab does not return the user login when the contributor's list is fetched. therefore, the name key is used to compare
the check command was broken because gitlab does not return the user login when fetching contributors. the name is now being used (because it is the only other data stored)
add 2 new items in the Configuration section: repoType and repoHost
Hi @machour , do you want to take a look? I've done a bit of refactoring as well, in order to move all interactions with github to its own folder, to allow for a better abstraction for gitlab. I made sure the existing unit tests kept working, and added my own tests to most of the code (but not all of it). I also tested it in a project I have on a private gitlab server, and it works like a charm :) I'd appreciate your input in order to change whatever necessary |
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.
@tigermarques this looks really promising!
I'll give it a deep review this afternoon. Could you meanwhile fix the whitespaces? It seems like you mixed tabs & spaces and some blocks are weirdly indented.
Please stick to 2 spaces for the indent.
Sure I'll look into it. I'm used to having eslint shout at me about that. I'll change the indents to two spaces |
Fixed, and I've added two new rules to the
This enforces what you asked me to change so that eslint shouts at me. Do you want me to push this as well? For the time being, it is only on my own |
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.
Changes implemented
@machour, have you had a chance to look at the code? |
@tigermarques I will try my best to do that today (I need to create a gitlab account and test everything so this might take me a while). Could you fix the little merge conflict? |
github.js and gitlab.js now check for status codes >= 400 and print the respective error message
Merge conflict fixed. Added the check for >= 400 status codes for both github and gitlab. |
If you want to use my user when testing in gitlab to add more contributors to a repo, fell free. It's jmarques. |
src/repo/gitlab.js
Outdated
}) | ||
.then(newRes => { | ||
const contributors = JSON.parse(newRes.body) | ||
if (newRes.statusCode >= 400) { |
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.
Some tabs leftovers (here and the two following lines)
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.
Sorry about that. Fixed
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.
This is an outstanding work @tigermarques, congratulations!
Still something to review in the check
command otherwise this looks really great! 🙌
src/repo/gitlab.js
Outdated
if (newRes.statusCode >= 400) { | ||
throw new Error(contributors.message) | ||
} | ||
return contributors.map(item => item.name) |
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.
So sad that GitLab doesn't return the username.
I tested by changing my name in the .allcontributorsrc
file to "Mehdi Acho".
Running the check command gives:
Missing contributors in .all-contributorsrc:
Mehdi Achour
It also should have mentioned the unknown contributor found (Acho).
This happens around line 108 in src/cli.js
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.
This comment got hidden as lines were changed. Don't forget to check 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.
You're right I had missed it! So basically the error is that it detects the Gitlab user is not in the file, but does not detect that the contributor in the file is not in Gitlab. Is that 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.
exactly "is not in the project's contributors as returned by Gitlab" to be precise
src/cli.js
Outdated
return util | ||
.check(configData.projectOwner, configData.projectName) | ||
return repo | ||
.getContributors(configData.projectOwner, configData.projectName, configData.repoType, configData.repoHost) | ||
.then(ghContributors => { |
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.
ghContributors
used to stand for GitHub Contributors.
Could you rename?
src/cli.js
Outdated
) | ||
const missingFromGithub = knownContributors.filter(login => { | ||
const missingFromGithub = knownContributors.filter(key => { |
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.
Same here, this needs to be renamed
ghContributors was specific to GitHub, and therefore the variable is renamed to be more generic
I've checked the comment now, and here is a test I produced:
Can you check if by any chance your contributions are of types that don't include
|
Gotcha, I didn't have a reaaaaaaally minor thingy: when the repo haven't got any contribution yet (just created), if you run check you'll get Might be better to catch it and output "no contributors found on GitLab" 🤔 |
…ound Message is "No contributors found on the GIthub repository
…ound Message is "No contributors found on the GitLab repository"
Good catch. I was returning the default message that Gitlab sent. |
Also, since this is a big change, and people are used to this lib working with GitHub only, it may be worth hinting about GitLab support. Maybe change the sentence
to read
under This solution in the README file |
Outstanding work @tigermarques 👏 👏 👏 👏 |
checkKey: 'login', | ||
defaultHost: 'https://github.com', | ||
linkToCommits: '<%= options.repoHost %>/<%= options.projectOwner %>/<%= options.projectName %>/commits?author=<%= contributor.login %>', | ||
linkToIssues: '<%= options.repoHost %>/<%= options.projectOwner %>/<%= options.projectName %>/issues?q=author%3A<%= contributor.login %>', |
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.
Could we add || "https://github.com"
here like we have for gitlab? It makes sense to me. Could you open up another PR for this @tigermarques?
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.
Actually, don't bother. I'll go ahead and do it really quick :)
What:
This change will introduce two new configurations:
repoType
represents the type of repository and is a choice betweengithub
andgitlab
(default isgithub
)repoHost
represents where the repository is hosted, and it's default ishttps://github.com
whenrepoType
isgithub
, andhttps://gitlab.com
whenrepoType
isgitlab
.Why:
These new configurations will allow to populate the contributors table with users that belong to registries other than https://github.com, which is currently the only one supported.
How:
By adding the two new configurations in the
init
step, and later using them while adding new contributors or generating the contributor list.Checklist: