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

(WIP) Add GitLab Backend #517

Closed
wants to merge 23 commits into from
Closed

(WIP) Add GitLab Backend #517

wants to merge 23 commits into from

Conversation

tech4him1
Copy link
Contributor

@tech4him1 tech4him1 commented Aug 8, 2017

- Summary

Add support for GitLab as a backend. This version does not support the editorial workflow. Fixes #57. This PR copies the code from #508, so those fixes can be used for this backend as well. It is also (re)based on #560 -- once that one is merged this will be rebased.

- Todos

  • Add an error message about Editorial Workflow being unsupported.
  • Cleanup code. The base code was copied from @Benaiah's GitHub refactor in Refactor API code for GitHub backend #508 and depends on some of the fixes in it. There are also probably some unused leftovers from the GitHub code that can be removed.
  • Add support for group/subgroup repos.
  • Make the request and fileExists functions more maintainable -- see TODOs in code.
  • Add a GitLab icon to the login screen 😄. This can wait for Cleanup Icons #522 unless somebody else has a solution.
  • Support custom GitLab instances (other than gitlab.com). I haven't tested this yet, but api_root should work.
  • Handle paginated directory contents
  • Add a non-intrusive re-auth popup when the OAuth token times out: WIP: Gentle re-authentication modal/popup. #560. This doesn't actually seem to be a problem yet, so we can do it later if necessary.
  • Support Git Gateway
  • Implement tests: WIP GitLab Tests. Backend tests are also a WIP for the GitHub backend as well ((WIP) Tests for GitHub API #515), so we should be able to copy those.
  • Support Editorial Workflow. This will likely have to be dramatically different from the GitHub implementation, so it has its own issue at Add Editorial Workflow support for GitLab and BitBucket backends #568.
  • Support implicit OAuth authentication (so no middle authentication server is needed).
  • Support search (with pagination). We may be able to use GitLab's search API, and just disable it for older versions of GitLab that don't have that API endpoint.

- Test plan

Manually tested with the example project and a "real" project.

- Description for the changelog

Add support for GitLab as a backend (simple workflow only).

@tech4him1 tech4him1 force-pushed the gitlab branch 2 times, most recently from c28b852 to 4cd83f9 Compare August 8, 2017 19:36
@tech4him1 tech4him1 mentioned this pull request Aug 12, 2017
@tech4him1 tech4him1 force-pushed the gitlab branch 9 times, most recently from 9ea2caf to c3ff76d Compare August 14, 2017 23:19
@tech4him1 tech4him1 changed the title WIP: Add GitLab Backend Add GitLab Backend Aug 14, 2017
@tech4him1
Copy link
Contributor Author

tech4him1 commented Aug 15, 2017

@zanedev brought up the fact that the current implementation does not work with OAuth access_tokens that expire. As far as I can tell, Netlify's OAuth server does not currently return refresh_tokens, so if left logged in, the CMS eventually just stops working. A user must log out and log back in to make the CMS start working again.

@tech4him1 tech4him1 changed the title Add GitLab Backend (WIP) Add GitLab Backend Aug 15, 2017
@tech4him1 tech4him1 self-assigned this Aug 17, 2017
@tech4him1 tech4him1 force-pushed the gitlab branch 2 times, most recently from 99d0ad9 to 1b8f2e8 Compare August 29, 2017 22:52
Copy link
Contributor

@Benaiah Benaiah left a comment

Choose a reason for hiding this comment

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

Quick review of request and fileExists in the GitLab API.

}
return Promise.all([response, response.text()]);
})
.catch(err => [err, null])
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be .catch(err => Promise.reject([err, null)) so the other .catch block catches and destructures it properly. This is my bad - it's the same way in my GH API refactor PR.

.catch(([errorValue, response]) => {
const errorMessageProp = (errorValue && errorValue.message) ? errorValue.message : null;
const message = errorMessageProp || (isString(errorValue) ? errorValue : "");
throw new APIError(message, response && response.status, 'GitHub', { response, errorValue });
Copy link
Contributor

Choose a reason for hiding this comment

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

Change 'GitHub' to 'GitLab'

}).then(() => true).catch((err) => {
// TODO: 404 can mean either the file does not exist, or if an API
// endpoint doesn't exist. Is there a better way to check for this?
if (err.status === 404) {return false;} else {throw err;}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can change this whole block to .catch(err => (err.status === 404 ? false : Promise.reject(err))). I think the 404 check is fine, unless GitLab has something more specific we can check (you can access the whole response object as err.meta).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that with a HEAD request, we don't actually get the content of the error message back, so we can't tell the difference.

@cbarrett
Copy link

cbarrett commented Oct 2, 2017

Is this still in progress? I'm interested in working on this (in fact have already started before I saw this.)

@tech4him1
Copy link
Contributor Author

tech4him1 commented Oct 2, 2017

@cbarrett @theetrain Yes, this is still in progress. Right now we have mostly been working on bugfixes and critical features for 1.0 (see https://github.com/netlify/netlify-cms/wiki/2017.09.13-Planning-Session for an update), but as soon as we get those done, we'll get back to this.

If you need to use it right now you should be able to rebase it onto master and use as-is.

@suprafly
Copy link

Would love to know when this is in.

@tech4him1 tech4him1 mentioned this pull request Nov 28, 2017
@nnyath
Copy link

nnyath commented Dec 3, 2017

@tech4him1 is the Netlify auth api currently supported/enabled for GitLab?

I've merged your gitlab branch with 0.7.6 and got it running but I'm facing a 'No Auth Provider Found' when the pop-up window attempts to access
https://api.netlify.com/auth?provider=gitlab&site_id=cms.netlify.com&scope=repo

Also, are there any plans for direct auth since GitLab supports implicit grant?

@tech4him1
Copy link
Contributor Author

@nnyath The Netlify Auth API does support GitLab, but you will still need to set it up like you do with the GitHub backend: https://www.netlify.com/docs/authentication-providers/#using-an-authentication-provider.

That's a very good point about implicit auth, and we've actually been discussing this within the team lately. @Benaiah @erquhart Is there any reason not to allow implicit auth with the backends that support it?

@Benaiah
Copy link
Contributor

Benaiah commented May 7, 2018

Development has moved to #1343, which refactors the CMS and the GitLab backend to use cursors for sophisticated pagination support. While development and code review will be done there, I will continue to update this PR as we hit milestones, since so many people are subscribed here for updates.

@Benaiah Benaiah closed this May 7, 2018
@Benaiah
Copy link
Contributor

Benaiah commented May 25, 2018

#1343 is now ready for review!

Benaiah and others added 23 commits June 4, 2018 18:41
them.

This is not optimal, but it is how the GitHub implementation works and
should be fixed later.
`hasWriteAccess` was not working in the case where permissions were
granted on a single group-owned repo, instead of the entire group.
@erquhart
Copy link
Contributor

erquhart commented Jun 4, 2018

Rebased and added a commit for single direction pagination support.

@erquhart erquhart closed this Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gitlab as backend.