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

Fixes based on github plugin for v12

Tey, Benjamin4c78ed6399cc
diff --git a/README.md b/README.md
index 2ebe59b4074..34daa473d91 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# openproject-gitlab-integration
-## NEW VERSION 2.0.0 (pre-release)
+## 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).
![OP-Gitlab](https://user-images.githubusercontent.com/14983519/143622798-13d1c50b-1186-46e0-a2da-9f50fb14a338.png)
@@ -132,6 +132,16 @@ PATH
openproject-webhooks
```
+Or
+
+```
+PATH
+ remote: modules/gitlab_integration
+ specs:
+ openproject-gitlab_integration (2.0.1)
+ openproject-webhooks
+```
+
Add the following in **Gemfile.modules**:
```
group :opf_plugins do
@@ -141,6 +151,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:
+
+```
+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):
+
+```
+ // /api/v3/(?:projectPath)/work_packages/(:workPackageId)/gitlab_merge_requests
+ public readonly gitlab_merge_requests = this.subResource('gitlab_merge_requests');
+```
+
+This line of code is necessary so that when precompiling the plugin assets they do not generate an error.
+
### 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.
diff --git a/frontend/module/git-actions-menu/git-actions-menu.component.ts b/frontend/module/git-actions-menu/git-actions-menu.component.ts
index c0efeb16045..80ecfe7b0f7 100644
--- a/frontend/module/git-actions-menu/git-actions-menu.component.ts
+++ b/frontend/module/git-actions-menu/git-actions-menu.component.ts
@@ -29,15 +29,15 @@
import copy from 'copy-text-to-clipboard';
import { Component, Inject, Input } from '@angular/core';
-import { WorkPackageResource } from 'core-app/modules/hal/resources/work-package-resource';
-import { I18nService } from 'core-app/modules/common/i18n/i18n.service';
import { GitActionsService } from '../git-actions/git-actions.service';
-import { OPContextMenuComponent } from 'core-app/components/op-context-menu/op-context-menu.component';
+import { ISnippet } from "core-app/features/plugins/linked/openproject-gitlab_integration/typings";
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
+import { OPContextMenuComponent } from "core-app/shared/components/op-context-menu/op-context-menu.component";
import {
OpContextMenuLocalsMap,
OpContextMenuLocalsToken
-} from 'core-app/components/op-context-menu/op-context-menu.types';
-import { ISnippet} from "core-app/modules/plugins/linked/openproject-gitlab_integration/typings";
+} from "core-app/shared/components/op-context-menu/op-context-menu.types";
+import { I18nService } from "core-app/core/i18n/i18n.service";
@Component({
diff --git a/frontend/module/git-actions-menu/git-actions-menu.directive.ts b/frontend/module/git-actions-menu/git-actions-menu.directive.ts
index 9275d0f38b7..62e54b0d74f 100644
--- a/frontend/module/git-actions-menu/git-actions-menu.directive.ts
+++ b/frontend/module/git-actions-menu/git-actions-menu.directive.ts
@@ -27,12 +27,13 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import {OpContextMenuItem} from 'core-components/op-context-menu/op-context-menu.types';
-import {OPContextMenuService} from 'core-components/op-context-menu/op-context-menu.service';
-import {Directive, ElementRef, Input} from '@angular/core';
-import {OpContextMenuTrigger} from 'core-components/op-context-menu/handlers/op-context-menu-trigger.directive';
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
-import {GitActionsMenuComponent} from './git-actions-menu.component';
+import { OpContextMenuItem } from 'core-app/shared/components/op-context-menu/op-context-menu.types';
+import { OPContextMenuService } from 'core-app/shared/components/op-context-menu/op-context-menu.service';
+import { Directive, ElementRef, Input } from '@angular/core';
+import { OpContextMenuTrigger } from 'core-app/shared/components/op-context-menu/handlers/op-context-menu-trigger.directive';
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
+import { GitActionsMenuComponent } from './git-actions-menu.component';
+
@Directive({
selector: '[gitActionsCopyDropdown]'
diff --git a/frontend/module/git-actions/git-actions.service.ts b/frontend/module/git-actions/git-actions.service.ts
index fec13a49918..7a86e1a05ba 100644
--- a/frontend/module/git-actions/git-actions.service.ts
+++ b/frontend/module/git-actions/git-actions.service.ts
@@ -27,28 +27,27 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-
-import {Injectable} from '@angular/core';
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
-import formatter from 'tickety-tick-formatter';
+import { Injectable } from '@angular/core';
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
// probably not providable in root when we want to cache the formatter and set custom templates
@Injectable({
providedIn: 'root',
})
export class GitActionsService {
- private formatter = formatter();
-
- public branchName(workPackage:WorkPackageResource):string {
- return(this.formatter.branch(this.formattingInput(workPackage)));
- }
-
- public commitMessage(workPackage:WorkPackageResource):string {
- return(this.formatter.commit(this.formattingInput(workPackage)));
- }
-
- public gitCommand(workPackage:WorkPackageResource):string {
- return(this.formatter.command(this.formattingInput(workPackage)));
+ private sanitizeBranchString(str:string):string {
+ // See https://stackoverflow.com/a/3651867 for how these rules came in.
+ // This sanitization tries to be harsher than those rules
+ return str
+ .replace(/&/g, 'and ') // & becomes and
+ .replace(/ +/g, '-') // Spaces become dashes
+ .replace(/[\000-\039]/g, '') // ASCII control characters are out
+ .replace(/\177/g, '') // DEL is out
+ .replace(/[#\\\/\?\*\~\^\:\{\}@\.\[\]'"]/g, '') // Some other characters with special rules are out
+ .replace(/^[-]+/g, '') // Dashes at the start are removed
+ .replace(/[-]+$/g, '') // Dashes at the end are removed
+ .replace(/-+/g, '-') // Multiple dashes in a row are deduped
+ .trim();
}
private formattingInput(workPackage: WorkPackageResource) {
@@ -62,4 +61,29 @@ export class GitActionsService {
id, type, title, url, description
});
}
-}
\ No newline at end of file
+
+ private sanitizeShellInput(str:string):string {
+ return `${str.replace(/'/g, '\\\'')}`;
+ }
+
+ public branchName(workPackage:WorkPackageResource):string {
+ const { type, id, title } = this.formattingInput(workPackage);
+ return `${this.sanitizeBranchString(type)}/${id}-${this.sanitizeBranchString(title)}`.toLocaleLowerCase();
+ }
+
+ public commitMessage(workPackage:WorkPackageResource):string {
+ const { title, id, description, url } = this.formattingInput(workPackage);
+ return `[#${id}] ${title}
+
+${description}
+
+${url}
+`.replace(/\n\n+/g, '\n\n');
+ }
+
+ public gitCommand(workPackage:WorkPackageResource):string {
+ const branch = this.branchName(workPackage);
+ const commit = this.commitMessage(workPackage);
+ return `git checkout -b '${this.sanitizeShellInput(branch)}' && git commit --allow-empty -m '${this.sanitizeShellInput(commit)}'`;
+ }
+}
diff --git a/frontend/module/gitlab-tab/gitlab-tab.component.ts b/frontend/module/gitlab-tab/gitlab-tab.component.ts
index f1abea8de1f..bcd36c1a093 100644
--- a/frontend/module/gitlab-tab/gitlab-tab.component.ts
+++ b/frontend/module/gitlab-tab/gitlab-tab.component.ts
@@ -27,11 +27,11 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import {Component, Input} from '@angular/core';
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
-import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
-import { TabComponent } from 'core-app/components/wp-tabs/components/wp-tab-wrapper/tab';
+import { Component, Input } from '@angular/core';
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
+import { TabComponent } from "core-app/features/work-packages/components/wp-tabs/components/wp-tab-wrapper/tab";
+import { I18nService } from "core-app/core/i18n/i18n.service";
+import { PathHelperService } from "core-app/core/path-helper/path-helper.service";
@Component({
selector: 'gitlab-tab',
diff --git a/frontend/module/hal/resources/gitlab-merge-request-resource.ts b/frontend/module/hal/resources/gitlab-merge-request-resource.ts
index 391d76deae6..23163b38f0b 100644
--- a/frontend/module/hal/resources/gitlab-merge-request-resource.ts
+++ b/frontend/module/hal/resources/gitlab-merge-request-resource.ts
@@ -27,7 +27,7 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import { HalResource } from 'core-app/modules/hal/resources/hal-resource';
+import { HalResource } from "core-app/features/hal/resources/hal-resource";
export class GitlabMergeRequestResource extends HalResource {
public get state() {
diff --git a/frontend/module/hal/resources/gitlab-pipelines-resource.ts b/frontend/module/hal/resources/gitlab-pipelines-resource.ts
index 26492f5b6a8..7e01eb4ccb6 100644
--- a/frontend/module/hal/resources/gitlab-pipelines-resource.ts
+++ b/frontend/module/hal/resources/gitlab-pipelines-resource.ts
@@ -27,7 +27,7 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import { HalResource } from 'core-app/modules/hal/resources/hal-resource';
+import { HalResource } from "core-app/features/hal/resources/hal-resource";
export class GitlabPipelineResource extends HalResource {
public get state() {
diff --git a/frontend/module/hal/resources/gitlab-user-resource.ts b/frontend/module/hal/resources/gitlab-user-resource.ts
index bbcca7937cc..3a18da80ba5 100644
--- a/frontend/module/hal/resources/gitlab-user-resource.ts
+++ b/frontend/module/hal/resources/gitlab-user-resource.ts
@@ -27,7 +27,7 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import { HalResource } from 'core-app/modules/hal/resources/hal-resource';
+import { HalResource } from "core-app/features/hal/resources/hal-resource";
export class GitlabUserResource extends HalResource {
public get state() {
diff --git a/frontend/module/main.ts b/frontend/module/main.ts
index b2a116a9e8f..75005fdac82 100644
--- a/frontend/module/main.ts
+++ b/frontend/module/main.ts
@@ -28,7 +28,10 @@
//++
import { Injector, NgModule } from '@angular/core';
-import { OpenprojectCommonModule } from 'core-app/modules/common/openproject-common.module';
+import { OPSharedModule } from 'core-app/shared/shared.module';
+import { OpenprojectTabsModule } from 'core-app/shared/components/tabs/openproject-tabs.module';
+import { WorkPackageTabsService } from 'core-app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-tabs.service';
+
import { GitlabTabComponent } from './gitlab-tab/gitlab-tab.component';
import { TabHeaderComponent } from './tab-header/tab-header.component';
@@ -37,8 +40,6 @@ import { GitActionsMenuDirective } from './git-actions-menu/git-actions-menu.dir
import { GitActionsMenuComponent } from './git-actions-menu/git-actions-menu.component';
import { WorkPackagesGitlabMrsService } from './tab-mrs/wp-gitlab-mrs.service';
import { MergeRequestComponent } from './merge-request/merge-request.component';
-import { WorkPackageTabsService } from "core-components/wp-tabs/services/wp-tabs/wp-tabs.service";
-import { OpenprojectTabsModule } from "core-app/modules/common/tabs/openproject-tabs.module";
export function initializeGitlabIntegrationPlugin(injector:Injector) {
const wpTabService = injector.get(WorkPackageTabsService);
@@ -53,7 +54,7 @@ export function initializeGitlabIntegrationPlugin(injector:Injector) {
@NgModule({
imports: [
- OpenprojectCommonModule,
+ OPSharedModule,
OpenprojectTabsModule,
],
providers: [
diff --git a/frontend/module/merge-request/merge-request.component.ts b/frontend/module/merge-request/merge-request.component.ts
index beb7c0b7a98..a787b9244e6 100644
--- a/frontend/module/merge-request/merge-request.component.ts
+++ b/frontend/module/merge-request/merge-request.component.ts
@@ -28,10 +28,10 @@
//++
import { Component, Input } from '@angular/core';
-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
-import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
import { GitlabPipelineResource } from '../hal/resources/gitlab-pipelines-resource';
import { IGitlabMergeRequestResource } from "../../../../../../../../modules/gitlab_integration/frontend/module/typings";
+import { PathHelperService } from "core-app/core/path-helper/path-helper.service";
+import { I18nService } from "core-app/core/i18n/i18n.service";
@Component({
selector: 'gitlab-merge-request',
diff --git a/frontend/module/tab-header/styles/tab-header.sass b/frontend/module/tab-header/styles/tab-header.sass
index 16ba6d0b05b..9e8f305eb22 100644
--- a/frontend/module/tab-header/styles/tab-header.sass
+++ b/frontend/module/tab-header/styles/tab-header.sass
@@ -44,4 +44,4 @@
font-weight: bold
font-size: 1rem
line-height: 32px
- text-transform: uppercase
\ No newline at end of file
+ text-transform: uppercase
diff --git a/frontend/module/tab-header/tab-header.component.ts b/frontend/module/tab-header/tab-header.component.ts
index c3ac939062a..3be83881047 100644
--- a/frontend/module/tab-header/tab-header.component.ts
+++ b/frontend/module/tab-header/tab-header.component.ts
@@ -27,9 +27,9 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import {Component, Input} from '@angular/core';
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
-import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
+import { Component, Input } from '@angular/core';
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
+import { I18nService } from "core-app/core/i18n/i18n.service";
@Component({
selector: 'tab-header',
diff --git a/frontend/module/tab-mrs/tab-mrs.component.ts b/frontend/module/tab-mrs/tab-mrs.component.ts
index e7325e4d221..85b6cb8b844 100644
--- a/frontend/module/tab-mrs/tab-mrs.component.ts
+++ b/frontend/module/tab-mrs/tab-mrs.component.ts
@@ -27,14 +27,13 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import {Component, Input, OnInit} from '@angular/core';
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
-import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
-import { APIV3Service } from 'core-app/modules/apiv3/api-v3.service';
-import { HalResourceService } from 'core-app/modules/hal/services/hal-resource.service';
-import { CollectionResource } from 'core-app/modules/hal/resources/collection-resource';
-import { ChangeDetectorRef } from '@angular/core';
+import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
+import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { HalResourceService } from "core-app/features/hal/services/hal-resource.service";
+import { CollectionResource } from "core-app/features/hal/resources/collection-resource";
import { IGitlabMergeRequestResource } from "../../../../../../../../modules/gitlab_integration/frontend/module/typings";
+import { I18nService } from "core-app/core/i18n/i18n.service";
@Component({
selector: 'tab-mrs',
diff --git a/frontend/module/tab-mrs/wp-gitlab-mrs.service.ts b/frontend/module/tab-mrs/wp-gitlab-mrs.service.ts
index 915455e2907..1e17b490f0a 100644
--- a/frontend/module/tab-mrs/wp-gitlab-mrs.service.ts
+++ b/frontend/module/tab-mrs/wp-gitlab-mrs.service.ts
@@ -27,11 +27,11 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import { WorkPackageResource } from 'core-app/modules/hal/resources/work-package-resource';
-import { HalResource } from 'core-app/modules/hal/resources/hal-resource';
+import { WorkPackageResource } from "core-app/features/hal/resources/work-package-resource";
+import { HalResource } from "core-app/features/hal/resources/hal-resource";
import { Injectable } from '@angular/core';
-import { ConfigurationService } from 'core-app/modules/common/config/configuration.service';
-import { WorkPackageLinkedResourceCache } from 'core-components/wp-single-view-tabs/wp-linked-resource-cache.service';
+import { ConfigurationService } from "core-app/core/config/configuration.service";
+import { WorkPackageLinkedResourceCache } from 'core-app/features/work-packages/components/wp-single-view-tabs/wp-linked-resource-cache.service';
@Injectable()
export class WorkPackagesGitlabMrsService extends WorkPackageLinkedResourceCache<HalResource[]> {
diff --git a/frontend/module/typings.d.ts b/frontend/module/typings.d.ts
index 64ff69f93fe..19bce8a38d5 100644
--- a/frontend/module/typings.d.ts
+++ b/frontend/module/typings.d.ts
@@ -27,13 +27,13 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import { TabDefinition } from "core-app/modules/common/tabs/tab.interface";
-import { HalResourceClass } from "core-app/modules/hal/resources/hal-resource";
+import { HalResourceClass } from 'core-app/modules/hal/resources/hal-resource';
+
export interface ISnippet {
- id: string;
- name: string;
- textToCopy: ()=>string
+ id:string;
+ name:string;
+ textToCopy:()=>string
}
export interface IGitlabMergeRequestResource extends HalResourceClass {
diff --git a/openproject-gitlab_integration.gemspec b/openproject-gitlab_integration.gemspec
index 8ebfbe18442..a01ae84ffe1 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.0'
+ s.version = '2.0.1'
s.authors = "Ben Tey"
s.email = "[email protected]"
s.homepage = "https://github.com/btey/openproject-gitlab-integration"