Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Better place for setup IDs of WP Status

Tey, Benjamin8297f54bce3e
diff --git a/README.md b/README.md
index 34daa473d91..070607b843f 100644
--- a/README.md
+++ b/README.md
@@ -1,103 +1,117 @@
# openproject-gitlab-integration
-## NEW VERSION 2.0.1 (pre-release)
-Based on the current Github integration (OpenProject 11 & 12), this plugin offers the same functionalities as the current plugin for Github (and something else). This version includes changes to the DB and a new view similar to the current Github tab. Only the management of "pipelines" is pending an open issue in Gitlab (https://gitlab.com/gitlab-org/gitlab/-/issues/345028).
+
+## NEW VERSION 2.0.2 (pre-release)
+
+Based on the current Github integration (OpenProject 12), this plugin offers the same functionalities as the current plugin for Github (and something else). This version includes changes to the DB and a new view similar to the current Github tab. Only the management of "pipelines" is pending an open issue in Gitlab (https://gitlab.com/gitlab-org/gitlab/-/issues/345028).
![OP-Gitlab](https://user-images.githubusercontent.com/14983519/143622798-13d1c50b-1186-46e0-a2da-9f50fb14a338.png)
-The events captured in the WP activity log are the same as in version 1.0, only this new version includes a UI with all linked MRs, their status, their labels and the last pipeline (pending the Gitlab issue). If you use manual installation, keep in mind that it requires precompiling the assets and updating the DB with new tables. If you want to test it, do it in a test environment, and if you want, share your results in case something needs to be corrected.
+The events captured in the WP activity log are the same as in version 1.0, only this new version includes a UI with all linked MRs, their status, their labels and the last pipeline *(pending the Gitlab issue)*.
+
+If you use **manual** installation, keep in mind that it requires precompiling the assets and updating the DB with new tables.
-The following readme file is pending review with updated documentation.
+In case of a **docker** installation, you will need to build your custom docker image (see issue [#3](https://github.com/btey/openproject-gitlab-integration/issues/3)).
## Introduction
-OpenProject module for integration with Gitlab (latest release tested is 14.4.1)
+OpenProject module for integration with Gitlab (latest release tested is 14.7.1)
This plugin is based on the current plugin to integrate Github with OpenProject (https://docs.openproject.org/system-admin-guide/github-integration).
-The reference system is the same as for GitHub integration. You can use a link to the work package or just use “OP#87” in the title or description in Gitlab.
+The reference system is the same as for GitHub integration. You can use a link to the work package or just use “OP#87” or "PP#87" in the title in Gitlab.
+
+> **Note about the references.** Whether or not to include the reference in certain places depends on the information that Gitlab sends through its webhook. If you include the reference in the title of an issue, the comments on the issue do not need to include the reference. The same will happen when you generate a Merge Request based on an Issue that already includes the reference; comments from that MR need not include the reference.
+
+#### Difference between OP and PP
+
+If you use `OP#` as a reference in an Issue or MR title, all comments will be replicated in OpenProject. However, sometimes you may only want to keep information about the status of an Issue/MR in OpenProject, but you don't want your comments to be published. In this case, you can use `PP#` as a reference. This way the comments will not be published in OpenProject. But if at any time one of your comments is of interest to you to be published in OpenProject you can use `OP#` *directly in that comment*. So only that comment will be published in OpenProject. The rest of the comments will remain private and will not be published.
## Available events captured in OpenProject
OpenProject will **add comments** to work package for the following events:
+
* Merge Request (Opened, Closed and Merged)
* Issue (Opened, Closed)
* Push commits in Merge Requests
* Comments (on Issues, Merge Request, Commits and Snippets)
+* *Pipelines (pending)*
OpenProject will **update WP status** in this events:
+
* Merge Request (opened) - Status: In progress (currently ID=7)
* Merge Request (merged) - Status: Developed (currently ID=8)
-> **Note about the status.** If you want to change the ID of the status you can do this in this section of the [code](https://github.com/btey/openproject-gitlab-integration/blob/58279c79035539bdd127d14e2fd148c06d85a15a/lib/open_project/gitlab_integration/notification_handlers.rb#L108-L111).
->
-> **Note about the references.** Whether or not to include the reference in certain places depends on the information that Gitlab sends through its webhook. If you include the reference in the title of an issue, the comments on the issue do not need to include the reference. The same will happen when you generate a Merge Request based on an Issue that already includes the reference; comments from that MR need not include the reference.
+> **Note about the status.** If you want to change the ID of the status you can do this in this section of the [code](https://github.com/btey/openproject-gitlab-integration/blob/master/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb#L40-L41). By default is *disabled*, you can enable it by setting to `true` this [lines](https://github.com/btey/openproject-gitlab-integration/blob/master/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb#L38-L39).
## Example workflow
A typical workflow on Gitlab side would be:
-1. **Create Issue.**
+1. **Create Issue.**
+
<img src="doc/op-issue-opened.png" width="500">
-
+
> **Issue Opened:** Issue 6 New contact form - OP#18 for Scrum project has been opened by Administrator.
2. **Comment on issue.**
-
+
If the reference is included in the title, the comments will not need a reference. By default, all comments will use the title as a reference.
<img src="doc/op-commented-in-issue.png" width="500">
> **Commented in Issue:** Administrator commented this WP in Issue 6 New contact form - OP#18 on Scrum project:
- >
+ >
> New comment on the issue with attachment.
3. **Create Merge Request.**
-
+
<img src="doc/op-mr-opened.png" width="500">
-
+
> **MR Opened:** Merge request 25 Draft: Resolve "New contact form - OP#18" for Scrum project has been opened by Administrator.
>
> **Status** changed from _Specified_
> **to** _In progress_
4. **Comment in Merge Request.**
-
+
<img src="doc/op-commented-in-mr.png" width="500">
-
+
> **Commented in MR:** Administrator commented this WP in Merge request 25 Draft: Resolve "New contact form - OP#18" on Scrum project:
>
> New comment on MR.
5. **Reference in other Issues or Merge Request (comments).**
-
+
If the reference is NOT included in the title of the Issue/MR, the comments will need a reference. In OpenProject the comment will be saved as "referenced" in Issue/MR.
-
+
<img src="doc/op-referenced-in-issue.png" width="500">
-
+
> **Referenced in Issue:** Administrator referenced this WP in Issue 2 New backend pipeline on Scrum project:
>
> OP#18 New comment about...
+ >
+ > **Note:** If you use the reference `PP#` in the title of the Issue/MR, you can use `OP#` in the comment to generate the same type of comment in OpenProject.
6. **New commit in Merge Request.**
-
+
<img src="doc/op-pushed-in-mr.png" width="500">
-
+
> **Pushed in MR:** Administrator pushed fca3d6fb to Scrum project at 2021-03-08T08:01:57+00:00:
>
> Update readme.md OP#18
7. **Comment in a new commit of the Merge Request.**
-
+
<img src="doc/op-referenced-in-commit.png" width="500">
-
+
> **Referenced in Commit:** Administrator referenced this WP in a Commit Note 0bf0e3e9 on Scrum project:
>
> This change is for OP#18.
8. **Merge Request merged (generates up to 3 events).**
-
+
<img src="doc/op-mr-merged-event-2.png" width="500">
-
+
> **Pushed in MR:** Administrator pushed 1da09cb4 to Scrum project at 2021-03-05T14:57:37+00:00:
>
> Merge branch '5-new-contact-form-op-18' into 'master'
@@ -107,23 +121,30 @@ A typical workflow on Gitlab side would be:
> Closes #6
>
> See merge request root/scrum!9
-
+
<img src="doc/op-mr-merged-event-3.png" width="500">
-
+
> **MR Merged:** Merge request 24 Resolve "New contact form - OP#18" for Scrum project has been merged by Administrator.
>
> **Status** changed from _In progress_
> **to** _Developed_
-
+
<img src="doc/op-mr-merged-event-4.png" width="500">
-
+
> **Issue Closed:** Issue 6 New contact form - OP#18 for Scrum project has been closed by Administrator.
## Configuration
-You will have to configure both OpenProject and Gitlab for the integration to work. But first you must modify **Gemfile.lock** and **Gemfile.modules** so that OpenProject detects the new module.
+For now, this plugin should be installed in the same place as the Github plugin that comes bundled with OpenProject.
+
+- **Github plugin path:** `modules/github_integration`
+
+- **Path to put Gitlab plugin:** `modules/gitlab_integration`
+
+You will have to configure both **OpenProject** and **Gitlab** for the integration to work. But first you must modify **Gemfile.lock** and **Gemfile.modules** so that OpenProject detects the new module.
Add the following in **Gemfile.lock**:
+
```
PATH
remote: modules/gitlab_integration
@@ -132,17 +153,20 @@ PATH
openproject-webhooks
```
-Or
+> **Note:** Use version 1.0.0 if you only want to capture the events as comments.
```
PATH
remote: modules/gitlab_integration
specs:
- openproject-gitlab_integration (2.0.1)
+ openproject-gitlab_integration (2.0.2)
openproject-webhooks
```
+> **Note:** Use version 2.0.2 if you want to capture the events as comments and see the new UI Tab with the linked Merge Requests.
+
Add the following in **Gemfile.modules**:
+
```
group :opf_plugins do
...
@@ -151,13 +175,21 @@ group :opf_plugins do
end
```
-**Update (2022-01-27):** Right now, as the plugin for Github works, it is required to add a line of code in the core of the OpenProject code before the precompilation of the assets in the following file:
+## Changes required in the OpenProject code
+
+Right now, as the plugin for Github works, it is required to add some lines of code in the core of the OpenProject code before the precompilation of the assets.
+
+Please modify the following files:
+
+#### 1) api-v3-work-package-paths.ts
+
+Path of the file that needs to be modified:
```
frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-package-paths.ts
```
-Add the following just after the line defining th github resource (after line 52):
+Add the following just after the line defining the Github resource (after line 52):
```
// /api/v3/(?:projectPath)/work_packages/(:workPackageId)/gitlab_merge_requests
@@ -166,7 +198,27 @@ Add the following just after the line defining th github resource (after line 52
This line of code is necessary so that when precompiling the plugin assets they do not generate an error.
-### OpenProject
+#### 2) work-package.rd
+
+Path of the file that needs to be modified:
+
+```
+app/models/work_package.rb
+```
+
+Add the following just after the line defining the Github table relation (after line 67):
+
+```
+has_and_belongs_to_many :gitlab_merge_requests
+```
+
+This line of code is necessary to display the content of the new Gitlab tab and not generate the error:
+
+```
+undefined method `gitlab_merge_requests' for #<WorkPackage:0x000056127ee75b30>
+```
+
+### The Gitlab Bot user in OpenProject
First you will need to create a user in OpenProject that will make the comments. The user will have to be added to each project with a role that allows them to comment on work packages and change status.
@@ -178,16 +230,27 @@ Once the user is created you need to generate an OpenProject API token for it to
* Click on generate in the API row.
* Copy the generated key. You can now configure the necessary webhook in Gitlab.
-### Gitlab
+### The webhook in Gitlab
In Gitlab you have to set up a webhook in each repository to be integrated with OpenProject.
You need to configure just two things in the webhook:
+
1. The URL must point to your OpenProject server’s Gitlab webhook endpoint (/webhooks/gitlab). Append it to the URL as a simple GET parameter named key. In the end the URL should look something like this:
-```
-http://openproject-url.com/webhooks/gitlab?key=ae278268
-```
-2. Enable the required triggers: Push events, Comments, Issues events, Merge request events
+
+ ```
+ http://openproject-url.com/webhooks/gitlab?key=ae278268
+ ```
+
+2. Enable the required triggers:
+
+ 1. Push events
+
+ 2. Comments
+
+ 3. Issues events
+
+ 4. Merge request events
Now the integration is set up on both sides and you can use it.
diff --git a/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb b/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb
index 3ac435a3eb4..c974fba83d2 100644
--- a/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb
+++ b/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb
@@ -37,6 +37,8 @@ module OpenProject::GitlabIntegration
def process(payload_params)
update_status_on_new_mr = false # true if you only reference one merge by work_package, else false.
update_status_on_merged = false # true if you only reference one merge by work_package, else false.
+ wp_status_id_on_new_mr = 7 # the id of the status.
+ wp_status_id_on_merged = 8 # the id of the status.
accepted_actions = %w[open update reopen]
accepted_actions_for_comments = %w[open reopen]
@@ -53,9 +55,9 @@ module OpenProject::GitlabIntegration
if (accepted_actions_for_comments.include? payload.object_attributes.action) || (accepted_states.include? payload.object_attributes.state)
comment_on_referenced_work_packages(work_packages, user, notes)
if payload.object_attributes.state == 'opened' && update_status_on_new_mr
- status_on_referenced_work_packages(work_packages, user, 7)
+ status_on_referenced_work_packages(work_packages, user, wp_status_id_on_new_mr)
elsif payload.object_attributes.state == 'merged' && update_status_on_merged
- status_on_referenced_work_packages(work_packages, user, 8)
+ status_on_referenced_work_packages(work_packages, user, wp_status_id_on_merged)
end
end
upsert_merge_request(work_packages)
diff --git a/openproject-gitlab_integration.gemspec b/openproject-gitlab_integration.gemspec
index a01ae84ffe1..755f066463e 100644
--- a/openproject-gitlab_integration.gemspec
+++ b/openproject-gitlab_integration.gemspec
@@ -31,7 +31,7 @@
Gem::Specification.new do |s|
s.name = "openproject-gitlab_integration"
- s.version = '2.0.1'
+ s.version = '2.0.2'
s.authors = "Ben Tey"
s.email = "[email protected]"
s.homepage = "https://github.com/btey/openproject-gitlab-integration"