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

Editorial Workflow support for GitLab #1817

Closed
wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 18, 2018

Summary

Editorial Workflow support for GitLab

It's essentially the same as for GitHub with slightly different API calls.
I tried to keep the code as close as possible between the backends, to make refactoring common things easier. (please check that for reference)
It's been years since the last time I used JavaScript, so I'm open for suggestions about coding style and best practices.

I added a couple of TODOs about things I was unsure about.
I didn't implement resolving conflicts or rebasing branches.

Fixes half of #568 (please see my comments there)

Test plan

We tried positive scenarios manually (CMS changes to branches, merge requests, metadata).
We didn't try every negative scenario (external changes to branches, merge requests, metadata).

We manually migrated our existing draft entries to unpublished entries.

Simple use case:

  1. Create new unpublished entry
  2. [GitLab] Check that the branch and merge requests is created
  3. Publish unpublished entry
  4. [GitLab] Check that the branch is deleted and merge requests is merged

Complex use case:

  1. Edit existing published entry
  2. [GitLab] Check that the branch and merge requests is created
  3. Edit unpublished entry
  4. [GitLab] Check that the branch and merge requests is updated
  5. Delete unpublished entry
  6. [GitLab] Check that the branch is deleted and merge requests is closed

A picture of a cute animal

GitLab - About Us:

Our Tanuki (Japanese for raccoon dog) logo symbolizes this with a smart animal that works in a group to achieve a common goal.

gitlab_logo

@verythorough
Copy link
Contributor

verythorough commented Oct 18, 2018

Deploy preview for netlify-cms-www ready!

Built with commit 0b661eb

https://deploy-preview-1817--netlify-cms-www.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Oct 18, 2018

Deploy preview for cms-demo ready!

Built with commit 0b661eb

https://deploy-preview-1817--cms-demo.netlify.com

// The Commits API doesn't support creating orphan branches.
// https://gitlab.com/gitlab-org/gitlab-ce/issues/2420 only works for empty repositories.
throw new Error(`Not Implemented - GitLab API does not support creating orphan branches.'`);
// TODO - rudolf - Update README / Installation and Configuration.
Copy link
Author

@ghost ghost Oct 18, 2018

Choose a reason for hiding this comment

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

TODO - rudolf - Update README / Installation and Configuration.

updatedItems => {
const sha = updatedItems[0].sha;
const filesList = updatedItems.map(item => ({ path: item.path, sha: item.sha }));
// TODO - rudolf - Why does it matter whether an asset store is in use?
Copy link
Author

@ghost ghost Oct 18, 2018

Choose a reason for hiding this comment

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

TODO - rudolf - Why does it matter whether an asset store is in use?

Copy link
Contributor

@erquhart erquhart Nov 26, 2018

Choose a reason for hiding this comment

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

When you upload an image to the repo, it creates a commit direct against the configured branch. If you save a workflow entry without publishing it, and then upload and use a new image in that entry, saving again without publishing, the entry will reference an image that doesn't exist in the PR (because the new image was committed direct to the base branch). Therefore, if images are being stored in the repo (no asset store), we rebase the pull request onto the latest commit on the base branch every time the unpublished entry is saved (but only if the base branch has changed).

Copy link
Contributor

Choose a reason for hiding this comment

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

And yes, this is silly and shouldn't be the case, but it currently is.


// eslint-disable-next-line no-unused-vars
forceMergeMR(mr, branch, objects) {
// TODO - rudolf - Why is this needed? How are merge conflicts possible?
Copy link
Author

Choose a reason for hiding this comment

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

TODO - rudolf - Why is this needed? How are merge conflicts possible? (see mergeMr)

Choose a reason for hiding this comment

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

Actually, this is the current documented behaviour:

If merge request is unable to be accepted (ie: Work in Progress, Closed, Pipeline Pending Completion, or Failed while requiring Success) - you’ll get a 405 and the error message ‘Method Not Allowed’

If it has some conflicts and can not be merged - you’ll get a 406 and the error message ‘Branch cannot be merged’

If the sha parameter is passed and does not match the HEAD of the source - you’ll get a 409 and the error message ‘SHA does not match HEAD of source branch’

If you don’t have permissions to accept this merge request - you’ll get a 401


// eslint-disable-next-line no-unused-vars
rebaseMR(mrNumber, branch, contentKey, metadata, sha) {
// TODO - rudolf - Why is this needed? How are assets affected by branches?
Copy link
Author

Choose a reason for hiding this comment

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

TODO - rudolf - Why is this needed? How are assets affected by branches? (see editorialWorkflowGit)

Choose a reason for hiding this comment

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

Depending on the setting for a GitLab repository, it might be only allowed to merge if a fast forward merge is possible.
That means if someone has merged something while you've created a new merge request you need to rebase in order to merge your own changes.

const metadataPath = `${key}.json`;
return this.checkMetadataBranch().then(() =>
this.uploadAndCommit(
null, // entry is not used
Copy link
Author

Choose a reason for hiding this comment

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

I assumed that entry is not used in uploadAndCommit, but we probably should use a separate method for metadata.

@ghost
Copy link
Author

ghost commented Oct 18, 2018

Test results

Commits:
gitlab - editorial workflow - commits

Merge Request - Closed:
gitlab - editorial workflow - merge request - closed

Merge Request - Merged:
gitlab - editorial workflow - merge request - merged

CMS - Workflow:
gitlab - editorial workflow - cms

Branches - Included `collection` and `slug` in branch name, to avoid conflicts between collections
Merge Requests - Changes to the branch are allowed, so HEAD is not checked against metadata
Edge - Replaced `finally` with `then` and `recover`, as it is not (yet) supported
@erquhart
Copy link
Contributor

This is crazy awesome @rudolf-zivver!! We're working on reviewing now, stay tuned.

@praveev
Copy link

praveev commented Nov 25, 2018

+1 any update on this feature?

@erquhart
Copy link
Contributor

We've given this some review, but it needs more - specifically testing. Merging changes to backends is shaky business without tests, as a small mistake could result in very big problems.

For folks in the community that want this, we could definitely use more eyes and reviews.

@rudolf-zivver has your team been using this in production? Any discoveries?

@Yttrium-tYcLief
Copy link

I hate to chime in where it's possibly unwelcome, but as the reference above shows, if I could get #1298 (or #2 or #1268) functional, then I could very extensively test this PR in production with a userbase of at least 20 or so users.

@ghost
Copy link
Author

ghost commented Dec 4, 2018

Let me get back to this PR next week. (deliverables, deadlines, etc.) ⏳ 🙁

Edit: It works for us in production, but we have a quite simple setup.

@jamezrin
Copy link

jamezrin commented Feb 8, 2019

The original MR author deleted its account, is there a chance for this to get assigned to someone else if that's even possible?

@erquhart
Copy link
Contributor

erquhart commented Feb 8, 2019

Sure is, just let us know.

// echo "# Netlify CMS\n\nThis branch is used by Netlify CMS to store metadata information for files, branches, merge requests.\n" > README.md
// git add README.md
// git commit -m "Initial commit by Netlify CMS"
// git push --set-upstream origin _netlify_cms
Copy link

@timaschew timaschew Mar 11, 2019

Choose a reason for hiding this comment

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

Why it's so important to create an orphan branch?

I mean it looks cleaner okay, but if this is not supported by GitLab, I don't see any problem to create just a normal branch or based on the first commit in the repo or even on the current master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely, we're aware that orphan refs are GitHub only - we're actually moving away from this model entirely and using more obvious methods like PR/MR labels to track status.

Here's an issue outlining that: #1669

And here's a WIP PR implementing it for GitHub: #1961

@verythorough
Copy link
Contributor

Adding this feature will require an update to the docs. Since they're in the same repo, you might as well include the changes in here. :)

Here's where you'll need to update:

Thanks!

@timaschew
Copy link

timaschew commented Mar 11, 2019

@Yttrium-tYcLief @jamezrin I got it running with a self hosted GitLab.
The happy path is working fine, but if there is a merge conflict or discussions hasn't been resolved yet then the publish (merge to master) doesn't work as well. If you're interested I can publish it in my fork.

@erquhart Any plans to show the current state of a merge request in the workflow, like pipeline/job status, if discussions/reviews has been resolved or not?

@erquhart
Copy link
Contributor

Currently we're only handling workflow status (draft/pending review/pending publish) and providing links to deploy previews when available. More robust status representation definitely makes sense, but it's not something we would take a PR for at the moment, needs a fair amount of product, arch, and design before we even know how to approach it.

@rico-ocepek
Copy link

Any news on this one? Would love to finally use this with my gitlab setup

@zomars
Copy link

zomars commented Jun 24, 2019

Almost two months without update? Is there something missing?

@erquhart
Copy link
Contributor

This is an abandoned PR.

#1817 (comment)

@erquhart
Copy link
Contributor

As the branch for this PR can no longer be updated, I've opened a new PR to continue development and discussion, see #2409.

@erquhart erquhart closed this Jun 26, 2019
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.

9 participants