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

feat: add support for GitLab repositories #84

Merged
merged 21 commits into from
Feb 23, 2018

Conversation

jgsmarques
Copy link
Contributor

@jgsmarques jgsmarques commented Feb 19, 2018

What:

This change will introduce two new configurations:

  • repoType represents the type of repository and is a choice between github and gitlab (default is github)
  • repoHost represents where the repository is hosted, and it's default is https://github.com when repoType is github, and https://gitlab.com when repoType is gitlab.

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:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

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-io
Copy link

codecov-io commented Feb 19, 2018

Codecov Report

Merging #84 into master will increase coverage by 0.75%.
The diff coverage is 62.96%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/util/index.js 100% <ø> (ø) ⬆️
src/cli.js 0% <0%> (ø) ⬆️
src/init/prompt.js 0% <0%> (ø) ⬆️
src/contributors/prompt.js 0% <0%> (ø) ⬆️
src/contributors/index.js 0% <0%> (ø) ⬆️
src/util/contribution-types.js 100% <100%> (ø) ⬆️
src/contributors/add.js 100% <100%> (ø) ⬆️
src/util/config-file.js 61.11% <25%> (-12.23%) ⬇️
src/repo/gitlab.js 39.39% <39.39%> (ø)
src/repo/index.js 83.78% <83.78%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab41caa...54304aa. Read the comment docs.

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
@jgsmarques jgsmarques changed the title [WIP] Support other sources other than Github.com Support other sources other than Github.com Feb 19, 2018
@jgsmarques
Copy link
Contributor Author

jgsmarques commented Feb 19, 2018

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

Copy link
Collaborator

@machour machour left a 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.

@jgsmarques
Copy link
Contributor Author

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

@jgsmarques
Copy link
Contributor Author

Fixed, and I've added two new rules to the eslintConfig section in package.json

{
    ...
    "no-mixed-spaces-and-tabs": "error",
    "indent": ["error", 2]
}

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 package.json

@jgsmarques
Copy link
Contributor Author

@machour , I found these two npm packages that might be an option to replace our interactions with github and gitlab. What do you think? Maybe I could consider it for a future PR after you have decided whether to keep this feature or not.

Copy link
Contributor Author

@jgsmarques jgsmarques left a comment

Choose a reason for hiding this comment

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

Changes implemented

@jgsmarques
Copy link
Contributor Author

@machour, have you had a chance to look at the code?

@machour
Copy link
Collaborator

machour commented Feb 23, 2018

@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
@jgsmarques
Copy link
Contributor Author

Merge conflict fixed. Added the check for >= 400 status codes for both github and gitlab.

@jgsmarques
Copy link
Contributor Author

jgsmarques commented Feb 23, 2018

If you want to use my user when testing in gitlab to add more contributors to a repo, fell free. It's jmarques.

})
.then(newRes => {
const contributors = JSON.parse(newRes.body)
if (newRes.statusCode >= 400) {
Copy link
Collaborator

@machour machour Feb 23, 2018

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)

Copy link
Contributor Author

@jgsmarques jgsmarques left a 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

Copy link
Collaborator

@machour machour left a 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! 🙌

if (newRes.statusCode >= 400) {
throw new Error(contributors.message)
}
return contributors.map(item => item.name)
Copy link
Collaborator

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

Copy link
Collaborator

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 ;)

Copy link
Contributor Author

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?

Copy link
Collaborator

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 => {
Copy link
Collaborator

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 => {
Copy link
Collaborator

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

@machour
Copy link
Collaborator

machour commented Feb 23, 2018

@tigermarques just making sure you've read this comment, which is blocking the approval:

screen shot 2018-02-23 at 12 26 32 pm

@jgsmarques
Copy link
Contributor Author

I've checked the comment now, and here is a test I produced:

  1. create a repo and commit with my user
  2. generate .all-contributorsrc
  3. add myself as contributor with doc contribution
  4. run check - does not detect anything as expected
  5. manually edit my name in the .all-contributorsrc
  6. run check:
    • Detects one entry in Missing contributors in .all-contributorsrc as expected
    • Does not detect any Unknown contributors because my contributions do not include neither code nor test
  7. manually edit my contributions in the .all-contributorsrc to add code
  8. run check - detects both differences now as expected

Can you check if by any chance your contributions are of types that don't include code or test. The code there is very explicit:

const missingFromRepo = knownContributors.filter(key => {
    return (
        !repoContributors.includes(key) &&
        (knownContributions[key].includes('code') ||
          knownContributions[key].includes('test'))
    )
})

@machour
Copy link
Collaborator

machour commented Feb 23, 2018

Gotcha, I didn't have a code or test contribution type. Added code and verified that it works like a charm.

reaaaaaaally minor thingy: when the repo haven't got any contribution yet (just created), if you run check you'll get 404 Not found printed without any explanations. This is because the gitlab api for contributors returns 404 in that case.

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"
@jgsmarques
Copy link
Contributor Author

Good catch. I was returning the default message that Gitlab sent.
For the sake of consistency, I added the same message for both github and gitlab (difference in the repo name only)

@machour
Copy link
Collaborator

machour commented Feb 23, 2018

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

This is a tool to help automate adding contributor acknowledgements according to the all-contributors specification.

to read

This is a tool to help automate adding contributor acknowledgements according to the all-contributors specification for your GitHub or GitLab repository.

under This solution in the README file

@machour machour changed the title Support other sources other than Github.com feat: add support for GitLab repositories Feb 23, 2018
@machour
Copy link
Collaborator

machour commented Feb 23, 2018

Outstanding work @tigermarques 👏 👏 👏 👏

@machour machour merged commit 152a1fe into all-contributors:master Feb 23, 2018
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 %>',
Copy link
Collaborator

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?

Copy link
Collaborator

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 :)

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.

4 participants