-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
Deploy preview for netlify-cms-www ready! Built with commit 0b661eb |
Deploy preview for cms-demo ready! Built with commit 0b661eb |
// 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. |
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.
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? |
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.
TODO - rudolf - Why does it matter whether an asset store is in use?
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.
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).
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.
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? |
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.
TODO - rudolf - Why is this needed? How are merge conflicts possible? (see mergeMr
)
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, 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? |
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.
TODO - rudolf - Why is this needed? How are assets affected by branches? (see editorialWorkflowGit
)
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.
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 |
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 assumed that entry
is not used in uploadAndCommit
, but we probably should use a separate method for metadata.
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
This is crazy awesome @rudolf-zivver!! We're working on reviewing now, stay tuned. |
+1 any update on this feature? |
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? |
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. |
The original MR author deleted its account, is there a chance for this to get assigned to someone else if that's even possible? |
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 |
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.
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.
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.
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! |
@Yttrium-tYcLief @jamezrin I got it running with a self hosted GitLab. @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? |
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. |
Any news on this one? Would love to finally use this with my gitlab setup |
Almost two months without update? Is there something missing? |
This is an abandoned PR. |
As the branch for this PR can no longer be updated, I've opened a new PR to continue development and discussion, see #2409. |
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:
Complex use case:
A picture of a cute animal
GitLab - About Us: