├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .gitlab-ci.yml ├── CHANGELOG_en_US.md ├── CHANGELOG_zh_CN.md ├── LICENSE ├── README.en_US.md ├── README.md ├── chart └── gitlab-service │ ├── .helmignore │ ├── Chart.yaml │ ├── README.md │ ├── README.md.gotmpl │ ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── ingress.yaml │ ├── pvc.yaml │ ├── service.yaml │ ├── serviceaccount.yaml │ └── tls-secrets.yaml │ └── values.yaml ├── docker └── Dockerfile ├── pom.xml └── src └── main ├── java └── io │ └── choerodon │ └── gitlab │ ├── GitlabServiceApplication.java │ ├── api │ ├── controller │ │ └── v1 │ │ │ ├── CommitController.java │ │ │ ├── ConfigController.java │ │ │ ├── ExternalProjectController.java │ │ │ ├── GroupsController.java │ │ │ ├── HookController.java │ │ │ ├── IssueController.java │ │ │ ├── JobController.java │ │ │ ├── LabelsController.java │ │ │ ├── MergeRequestController.java │ │ │ ├── MileStoneController.java │ │ │ ├── NotesController.java │ │ │ ├── PipelineController.java │ │ │ ├── PipelineScheduleController.java │ │ │ ├── ProjectsController.java │ │ │ ├── ReleaseController.java │ │ │ ├── RepositoryController.java │ │ │ └── UserController.java │ └── vo │ │ ├── CommitStatuseVO.java │ │ ├── CommitVO.java │ │ ├── FileCreationVO.java │ │ ├── FileDeleteVO.java │ │ ├── GitlabTransferVO.java │ │ ├── GitlabUserReqDTO.java │ │ ├── GroupVO.java │ │ ├── IssueVO.java │ │ ├── LabelVO.java │ │ ├── MemberVO.java │ │ ├── MergeRequestVO.java │ │ ├── MileStoneVO.java │ │ ├── PipelineVO.java │ │ ├── UserWithPassword.java │ │ └── VariableVO.java │ ├── app │ ├── aop │ │ └── RedisLimitAspect.java │ └── service │ │ ├── CommitService.java │ │ ├── ConfigService.java │ │ ├── ExternalProjectService.java │ │ ├── GroupService.java │ │ ├── HookService.java │ │ ├── IssueService.java │ │ ├── JobService.java │ │ ├── LabelsService.java │ │ ├── MergeRequestService.java │ │ ├── MileStoneService.java │ │ ├── NotesService.java │ │ ├── PipelineScheduleService.java │ │ ├── PipelineService.java │ │ ├── ProjectService.java │ │ ├── ReleaseService.java │ │ ├── RepositoryService.java │ │ ├── UserService.java │ │ └── impl │ │ ├── CommitServiceImpl.java │ │ ├── ConfigServiceImpl.java │ │ ├── ExternalProjectServiceImpl.java │ │ ├── GroupServiceImpl.java │ │ ├── HookServiceImpl.java │ │ ├── IssueServiceImpl.java │ │ ├── JobServiceImpl.java │ │ ├── LabelsServiceImpl.java │ │ ├── MergeRequestServiceImpl.java │ │ ├── MileStoneServiceImpl.java │ │ ├── NotesServiceImpl.java │ │ ├── PipelineScheduleServiceImpl.java │ │ ├── PipelineServiceImpl.java │ │ ├── ProjectServiceImpl.java │ │ ├── ReleaseServiceImpl.java │ │ ├── RepositoryServiceImpl.java │ │ └── UserServiceImpl.java │ └── infra │ ├── common │ ├── client │ │ └── Gitlab4jClient.java │ ├── config │ │ └── GitlabHealthy.java │ └── exception │ │ ├── GitlabBranchException.java │ │ ├── GitlabExceptionHandler.java │ │ └── MergeRequestNotFoundException.java │ ├── dto │ └── AppExternalConfigDTO.java │ ├── enums │ └── ExternalAppAuthTypeEnum.java │ └── util │ └── ExternalGitlabApiUtil.java └── resources ├── application.yml ├── bootstrap.yml ├── db ├── event_msg_record.groovy └── event_producer_record.groovy └── messages ├── messages_en_US.properties └── messages_zh_CN.properties /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Make sure these boxes are checked before submitting your issue - thank you! 2 | 3 | - [ ] I have checked the Choerodon logs and included it here as text if any 4 | - [ ] I have reproduced the issue with at least the latest released version of Choerodon 5 | - [ ] I have checked the issue tracker for the same issue and I haven't found one similar 6 | 7 | 8 | ### Choerodon version 9 | 10 | 11 | ### Expected results 12 | 13 | 14 | ### Actual results 15 | 16 | 17 | ### Steps to reproduce -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | application-default.yml -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | include: https://api.choerodon.com.cn/devops/v1/projects/261899051275677696/ci_contents/pipelines/30184d36-f36d-42a4-8e0e-1805e7686081/content.yaml 2 | 3 | #include: https://api.choerodon.com.cn/devops/v1/projects/1529/ci_contents/pipelines/2ab84ef8-bb06-478b-bb7f-deaeb93227bb/content.yaml 4 | # 5 | ##image: registry.cn-shanghai.aliyuncs.com/c7n/cibase:0.9.1 6 | ## 7 | ##stages: 8 | ## - build 9 | ## - release 10 | ## 11 | ##build: 12 | ## stage: build 13 | ## script: 14 | ## - update_pom_version 15 | ## - mvn package spring-boot:repackage 16 | ## - mv target/app.jar $PWD/docker 17 | ## - kaniko -c $PWD/docker -f $PWD/docker/Dockerfile -d ${DOCKER_REGISTRY}/${GROUP_NAME}/${PROJECT_NAME}:${CI_COMMIT_TAG} 18 | ## 19 | ##release: 20 | ## stage: release 21 | ## script: 22 | ## - chart_build 23 | ## 24 | ##maven-deploy-snapshot: 25 | ## stage: build 26 | ## script: 27 | ## - mvn clean install -Dmaven.springboot.skip=true -DskipTests=true deploy -DaltDeploymentRepository=${CHOERODON_SNAPSHOT_REPOSITORY_ID}::default::${CHOERODON_SNAPSHOT_URL} -Ddeploy.classifier=exec 28 | ## except: 29 | ## - tags 30 | ## 31 | ##maven-deploy-release: 32 | ## stage: build 33 | ## script: 34 | ## - mvn clean install -Dmaven.springboot.skip=true -DskipTests=true deploy -DaltDeploymentRepository=${CHOERODON_RELEASE_REPOSITORY_ID}::default::${CHOERODON_RELEASE_URL} -Ddeploy.classifier=exec 35 | ## only: 36 | ## - tags 37 | ## 38 | ##.auto_devops: &auto_devops | 39 | ## http_status_code=`curl -o .auto_devops.sh -s -m 10 --connect-timeout 10 -w %{http_code} "${CHOERODON_URL}/devops/ci?token=${Token}&type=microservice"` 40 | ## if [ "$http_status_code" != "200" ]; then 41 | ## cat .auto_devops.sh 42 | ## exit 1 43 | ## fi 44 | ## source .auto_devops.sh 45 | ## 46 | ##before_script: 47 | ## - *auto_devops -------------------------------------------------------------------------------- /CHANGELOG_en_US.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to gitlab-service will be documented in this file. 3 | 4 | 5 | ## [1.0.0] - 2021-06-18 6 | ### Changed 7 | - Upgrading hzero dependency on version 1.6.4 8 | 9 | ## [0.22.1] - 2020-08-01 10 | ### Added 11 | - Add Apis about GitLab pipelines 12 | 13 | ### Changed 14 | - changed framework to Hzero 15 | 16 | ## [0.7.0] - 2018-06-29 17 | ### Added 18 | - Gitlab new version v11.0.1 supported. 19 | 20 | ## [0.6.0] - 2018-06-10 21 | ### Changed 22 | - Reconfigure gitlab-service to change the way of value passing. -------------------------------------------------------------------------------- /CHANGELOG_zh_CN.md: -------------------------------------------------------------------------------- 1 | # 更新日志 2 | 这个文件记录gitlab-service所有版本的重大变动。 3 | 4 | ## [1.0.0] - 2021-06-18 5 | ### 改变 6 | - 升级hzero依赖版本为1.0.0 7 | 8 | 9 | ## [0.22.1] - 2020-08-01 10 | ### 新增 11 | - 添加GitLab流水线相关接口 12 | 13 | ### 改变 14 | - 更改父依赖为hzero 15 | 16 | ## [0.7.0] - 2018-06-29 17 | ### 新增 18 | - 支持gitlab升级为新版本v11.0.1。 19 | 20 | ## [0.6.0] - 2018-06-10 21 | ### 改变 22 | - 为了修改传值模式重构gitlab-service。 -------------------------------------------------------------------------------- /README.en_US.md: -------------------------------------------------------------------------------- 1 | English | [简体中文](./README.md) 2 | 3 | # Gitlab Service 4 | `Gitlab Service` is responsible for interacting with gitlab by introducing an external java client, this client directly calls the api provided by gitlab,Then gitlab-service handles gitlab logical requests from other services 5 | 6 | ## Feature 7 | `Gitlab Service` contains features as follows: 8 | - Group Management 9 | 10 | This function is used to manage Gitlab's group, including creating projects, deleting projects, querying projects, etc. 11 | 12 | - WebHook Management 13 | 14 | This function is used to manage Gitlab's WebHook, including creating WebHook, querying WebHook, etc. 15 | 16 | - Issue Management 17 | 18 | This function is used to manage Gitlab's issue, including create issue , update issue, close issue and other operations. 19 | 20 | - Label Management 21 | 22 | This function is used to manage Gitlab's labels, including querying label, deleting label, subscribing to labels, and so on. 23 | 24 | - Merge Request Management 25 | 26 | This function is used to manage Gitlab's Merge Request, including create, delete, query Merge Request and other operations. 27 | 28 | - Project Management 29 | 30 | This feature is used to manage Gitlab's projects, including creating , updating, deleting projects, and adding and removing Project members. 31 | 32 | - User Management 33 | This function is used to manage the User of Gitlab, including creating, updating, verifying the existence of User mailbox and other operations. 34 | 35 | ## Requirements 36 | - JDK-8 37 | - [Maven](http://www.maven-sf.com/) 38 | - [MySQL](https://www.mysql.com) 39 | - [Gitlab](https://gitlab.com) 40 | - [Kafka](https://kafka.apache.org) 41 | 42 | ## Installation and Getting Started 43 | 1. init database 44 | 45 | ```sql 46 | CREATE USER 'choerodon'@'%' IDENTIFIED BY "choerodon"; 47 | CREATE DATABASE gitlab_service DEFAULT CHARACTER SET utf8; 48 | GRANT ALL PRIVILEGES ON gitlab_service.* TO choerodon@'%'; 49 | FLUSH PRIVILEGES; 50 | ``` 51 | 2. run command as follow or run `GitlabServiceApplication` in IntelliJ IDEA 52 | 53 | ```bash 54 | mvn clean spring-boot:run 55 | ``` 56 | 57 | ## Service dependencies 58 | - `eureka-server`L Register & configure center 59 | - `oauth-server` authentication center 60 | - `MySQL`: gitlab_service 61 | 62 | ## Reporting Issues 63 | If you find any shortcomings or bugs, please describe them in the [issue](https://github.com/choerodon/choerodon/issues/new?template=issue_template.md). 64 | 65 | ## Link 66 | [Update Log](CHANGELOG_en_US.md) 67 | 68 | ## How to Contribute 69 | Pull requests are welcome! [Follow](https://github.com/choerodon/choerodon/blob/master/CONTRIBUTING.md) to know for more information on how to contribute. 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 简体中文 | [English](./README.en_US.md) 2 | 3 | # Gitlab Service 4 | 5 | `Gitlab Service`通过引入外部java客户端与Gitlab进行交互。该客户端通过直接调用Gitlab提供的api,处理来自其他服务的Gitlab请求。 6 | 7 | ## 功能 8 | 9 | - 项目组管理 10 | 11 | 此功能用于对Gitlab的group进行管理,包括创建、删除、查询项目以及添加、移除、查询项目组成员等操作。 12 | 13 | - WebHook管理 14 | 15 | 此功能用于对Gitlab的ProjectHook进行管理,包括创建和查询ProjectHook详情等操作。 16 | 17 | - 问题管理 18 | 19 | 此功能用于对Gitlab的Issue进行管理,包括创建、更新、关闭Issue等操作。 20 | 21 | - Label管理 22 | 23 | 此功能用于对Gitlab的Label进行管理,包括查询、删除、订阅Label等操作。 24 | 25 | - Merge Request管理 26 | 27 | 此功能用于对Gitlab的Merge Request进行管理,包括创建、删除、查询Merge Request等操作。 28 | 29 | - 项目管理 30 | 31 | 此功能用于对Gitlab的Project进行管理,包括创建、更新、删除项目以及添加、移除项目成员等操作。 32 | 33 | - 用户管理 34 | 35 | 此功能用于对Gitlab的User进行管理,包括创建、更新、校验用户邮箱是否存在等操作。 36 | 37 | ## 环境依赖 38 | 39 | - JDK-8 40 | - [Maven](http://www.maven-sf.com/) 41 | - [MySQL](https://www.mysql.com) 42 | - [Gitlab](https://gitlab.com) 43 | - [Kafka](https://kafka.apache.org) 44 | 45 | 46 | ## 安装与启动 47 | 48 | 1. 初始化数据库 49 | ```sql 50 | CREATE USER 'choerodon'@'%' IDENTIFIED BY "choerodon"; 51 | CREATE DATABASE gitlab_service DEFAULT CHARACTER SET utf8; 52 | GRANT ALL PRIVILEGES ON gitlab_service.* TO choerodon@'%'; 53 | FLUSH PRIVILEGES; 54 | ``` 55 | 56 | 2. 执行下列命令或在 IntelliJ IDEA 中运行`GitlabServiceApplication`类 57 | 58 | ```bash 59 | mvn clean spring-boot:run 60 | ``` 61 | 62 | ## 服务依赖 63 | 64 | - `eureka-server`: 注册&配置中心 65 | - `oauth-server` 认证中心 66 | - `MySQL`: gitlab_service 数据库 67 | 68 | ## 问题报告 69 | 70 | 如果您发现任何缺陷或bug,请在 [问题报告](https://github.com/choerodon/choerodon/issues/new?template=issue_template.md) 中提出 71 | 72 | ## 链接 73 | 74 | [更新日志](CHANGELOG_zh_CN.md) 75 | 76 | ## 贡献 77 | 78 | 欢迎贡献代码! [如何贡献](https://github.com/choerodon/choerodon/blob/master/CONTRIBUTING.md) -------------------------------------------------------------------------------- /chart/gitlab-service/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | -------------------------------------------------------------------------------- /chart/gitlab-service/Chart.yaml: -------------------------------------------------------------------------------- 1 | annotations: 2 | category: Infrastructure 3 | apiVersion: v2 4 | appVersion: 2.0.0 5 | dependencies: 6 | - name: common 7 | repository: https://openchart.choerodon.com.cn/choerodon/c7n 8 | version: 1.x.x 9 | description: Gitlab service of Choerodon. 10 | engine: gotpl 11 | home: https://github.com/open-hand/gitlab-service/tree/master/chart/gitlab-service 12 | icon: https://ui-avatars.com/api/?name=gitlab-service 13 | keywords: 14 | - choerodon 15 | - gitlab 16 | maintainers: 17 | - email: zhuchiyu@vip.hand-china.com 18 | name: choerodon 19 | url: https://choerodon.io 20 | name: gitlab-service 21 | sources: 22 | - https://github.com/open-hand/gitlab-service 23 | - https://gitee.com/open-hand/gitlab-service 24 | version: 2.0.0 25 | -------------------------------------------------------------------------------- /chart/gitlab-service/README.md.gotmpl: -------------------------------------------------------------------------------- 1 | {{ template "chart.header" . }} 2 | {{ template "chart.description" . }} 3 | 4 | ## Installing the Chart 5 | 6 | To install the chart with the release name `{{ template "chart.name" . }}`: 7 | 8 | ```console 9 | $ helm repo add c7n https://openchart.choerodon.com.cn/choerodon/c7n 10 | $ helm repo update 11 | $ helm install {{ template "chart.name" . }} c7n/{{ template "chart.name" . }} 12 | ``` 13 | 14 | Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. 15 | 16 | ## Uninstalling the Chart 17 | 18 | ```bash 19 | $ helm delete {{ template "chart.name" . }} 20 | ``` 21 | 22 | {{ template "chart.requirementsSection" . }} 23 | 24 | {{ template "chart.valuesSection" . }} 25 | 26 | {{ template "chart.maintainersSection" . }} 27 | -------------------------------------------------------------------------------- /chart/gitlab-service/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | ** Please be patient while the chart is being deployed ** 2 | 3 | Verify deployment: 4 | 5 | curl -s $(kubectl get po --namespace {{ .Release.Namespace }} \ 6 | -l choerodon.io/release={{ .Release.Name }} \ 7 | -o jsonpath="{.items[0].status.podIP}"):{{ .Values.containerPort.actuatorPort }}/actuator/health | jq -r .status 8 | 9 | If the following similar information appears, it is a successful deployment: 10 | 11 | UP -------------------------------------------------------------------------------- /chart/gitlab-service/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | 3 | {{/* 4 | Return the proper image name 5 | */}} 6 | {{- define "server.image" -}} 7 | {{ include "common.images.image" (dict "imageRoot" .Values.image "chart" .Chart "global" .Values.global) }} 8 | {{- end -}} 9 | 10 | {{/* 11 | Return the proper skywalking image name 12 | */}} 13 | {{- define "skywalking.image" -}} 14 | {{ include "common.images.image" (dict "imageRoot" .Values.skywalking "chart" .Chart "global" .Values.global) }} 15 | {{- end -}} 16 | 17 | {{/* 18 | Return the proper java base image name 19 | */}} 20 | {{- define "base.image" -}} 21 | {{ include "common.images.image" (dict "imageRoot" .Values.base "chart" .Chart "global" .Values.global) }} 22 | {{- end -}} 23 | 24 | {{/* 25 | Return the proper Docker Image Registry Secret Names 26 | */}} 27 | {{- define "server.imagePullSecrets" -}} 28 | {{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.base .Values.skywalking) "global" .Values.global) -}} 29 | {{- end -}} 30 | 31 | {{/* 32 | Get the workingDir. 33 | */}} 34 | {{- define "server.workingDir" -}} 35 | {{- printf "%s" (default .Values.persistence.mountPath .Values.workingDir) -}} 36 | {{- end -}} 37 | 38 | {{/* 39 | Get the credentials secret. 40 | */}} 41 | {{- define "server.secretName" -}} 42 | {{- if .Values.global.server.existingSecret }} 43 | {{- printf "%s" .Values.global.server.existingSecret -}} 44 | {{- else if .Values.existingSecret -}} 45 | {{- printf "%s" .Values.existingSecret -}} 46 | {{- else -}} 47 | {{- printf "%s" (include "common.names.fullname" .) -}} 48 | {{- end -}} 49 | {{- end -}} 50 | 51 | {{/* 52 | Return true if a PVC object should be created 53 | */}} 54 | {{- define "server.createPVC" -}} 55 | {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} 56 | {{- true -}} 57 | {{- end -}} 58 | {{- end -}} 59 | 60 | {{/* 61 | Return the PVC name 62 | */}} 63 | {{- define "server.claimName" -}} 64 | {{- if and .Values.persistence.existingClaim }} 65 | {{- printf "%s" (tpl .Values.persistence.existingClaim $) -}} 66 | {{- else -}} 67 | {{- printf "%s" (include "common.names.fullname" .) -}} 68 | {{- end -}} 69 | {{- end -}} 70 | 71 | {{/* 72 | Returns the proper service account name depending if an explicit service account name is set 73 | in the values file. If the name is not set it will default to either common.names.fullname if serviceAccount.create 74 | is true or default otherwise. 75 | */}} 76 | {{- define "server.serviceAccountName" -}} 77 | {{- if .Values.serviceAccount.create -}} 78 | {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }} 79 | {{- else -}} 80 | {{ default "default" .Values.serviceAccount.name }} 81 | {{- end -}} 82 | {{- end -}} 83 | -------------------------------------------------------------------------------- /chart/gitlab-service/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled }} 2 | apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} 3 | kind: Ingress 4 | metadata: 5 | name: {{ include "common.names.fullname" . }} 6 | namespace: {{ .Release.Namespace | quote }} 7 | labels: {{- include "common.labels.standard" . | nindent 4 }} 8 | {{- if .Values.commonLabels }} 9 | {{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }} 10 | {{- end }} 11 | annotations: 12 | {{- if .Values.commonAnnotations }} 13 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} 14 | {{- end }} 15 | {{- if .Values.ingress.annotations }} 16 | {{- include "common.tplvalues.render" (dict "value" .Values.ingress.annotations "context" $) | nindent 4 }} 17 | {{- end }} 18 | spec: 19 | {{- if and .Values.ingress.ingressClassName (eq "true" (include "common.ingress.supportsIngressClassname" .)) }} 20 | ingressClassName: {{ .Values.ingress.ingressClassName | quote }} 21 | {{- end }} 22 | rules: 23 | {{- if .Values.ingress.hostname }} 24 | - host: {{ include "common.tplvalues.render" ( dict "value" .Values.ingress.hostname "context" $ ) }} 25 | http: 26 | paths: 27 | {{- if .Values.ingress.extraPaths }} 28 | {{- toYaml .Values.ingress.extraPaths | nindent 10 }} 29 | {{- end }} 30 | - path: {{ .Values.ingress.path }} 31 | {{- if eq "true" (include "common.ingress.supportsPathType" .) }} 32 | pathType: {{ .Values.ingress.pathType }} 33 | {{- end }} 34 | backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" .) "servicePort" "server" "context" $) | nindent 14 }} 35 | {{- end }} 36 | {{- range .Values.ingress.extraHosts }} 37 | - host: {{ include "common.tplvalues.render" ( dict "value" .name "context" $ ) }} 38 | http: 39 | paths: 40 | - path: {{ default "/" .path }} 41 | {{- if eq "true" (include "common.ingress.supportsPathType" $) }} 42 | pathType: {{ default "ImplementationSpecific" .pathType }} 43 | {{- end }} 44 | backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" $) "servicePort" "server" "context" $) | nindent 14 }} 45 | {{- end }} 46 | {{- if or (and .Values.ingress.tls (or (include "common.ingress.certManagerRequest" ( dict "annotations" .Values.ingress.annotations )) .Values.ingress.selfSigned)) .Values.ingress.extraTls }} 47 | tls: 48 | {{- if and .Values.ingress.tls (or (include "common.ingress.certManagerRequest" ( dict "annotations" .Values.ingress.annotations )) .Values.ingress.selfSigned) }} 49 | - hosts: 50 | - {{ .Values.ingress.hostname | quote }} 51 | secretName: {{ printf "%s-tls" .Values.ingress.hostname }} 52 | {{- end }} 53 | {{- if .Values.ingress.extraTls }} 54 | {{- include "common.tplvalues.render" (dict "value" .Values.ingress.extraTls "context" $) | nindent 4 }} 55 | {{- end }} 56 | {{- end }} 57 | {{- end }} 58 | 59 | -------------------------------------------------------------------------------- /chart/gitlab-service/templates/pvc.yaml: -------------------------------------------------------------------------------- 1 | {{- if (include "server.createPVC" .) }} 2 | kind: PersistentVolumeClaim 3 | apiVersion: v1 4 | metadata: 5 | name: {{ include "common.names.fullname" . }} 6 | namespace: {{ .Release.Namespace }} 7 | labels: {{- include "common.labels.standard" . | nindent 4 }} 8 | {{- if .Values.commonLabels }} 9 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }} 10 | {{- end }} 11 | {{- if or .Values.persistence.annotations .Values.commonAnnotations }} 12 | annotations: 13 | {{- if .Values.persistence.annotations }} 14 | {{- include "common.tplvalues.render" ( dict "value" .Values.persistence.annotations "context" $ ) | nindent 4 }} 15 | {{- end }} 16 | {{- if .Values.commonAnnotations }} 17 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} 18 | {{- end }} 19 | {{- end }} 20 | spec: 21 | accessModes: 22 | {{- range .Values.persistence.accessModes }} 23 | - {{ . | quote }} 24 | {{- end }} 25 | resources: 26 | requests: 27 | storage: {{ .Values.persistence.size | quote }} 28 | {{- include "common.storage.class" (dict "persistence" .Values.persistence "global" .Values.global) | nindent 2 }} 29 | {{- end }} 30 | -------------------------------------------------------------------------------- /chart/gitlab-service/templates/service.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.service.enabled -}} 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: {{ include "common.names.fullname" . }} 6 | namespace: {{ .Release.Namespace }} 7 | labels: {{- include "common.labels.standard" . | nindent 4 }} 8 | {{- if .Values.commonLabels }} 9 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }} 10 | {{- end }} 11 | {{- if or .Values.service.annotations .Values.commonAnnotations }} 12 | annotations: 13 | {{- if .Values.service.annotations }} 14 | {{- include "common.tplvalues.render" ( dict "value" .Values.service.annotations "context" $ ) | nindent 4 }} 15 | {{- end }} 16 | {{- if .Values.commonAnnotations }} 17 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} 18 | {{- end }} 19 | {{- end }} 20 | spec: 21 | type: {{ .Values.service.type }} 22 | {{- if (or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort")) }} 23 | externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }} 24 | {{- end }} 25 | {{ if eq .Values.service.type "LoadBalancer" }} 26 | loadBalancerSourceRanges: {{ .Values.service.loadBalancerSourceRanges }} 27 | {{ end }} 28 | {{- if (and (eq .Values.service.type "LoadBalancer") (not (empty .Values.service.loadBalancerIP))) }} 29 | loadBalancerIP: {{ .Values.service.loadBalancerIP }} 30 | {{- end }} 31 | ports: 32 | - name: server 33 | port: {{ .Values.service.port.server }} 34 | targetPort: server 35 | {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }} 36 | nodePort: {{ .Values.service.nodePort.server }} 37 | {{- else if eq .Values.service.type "ClusterIP" }} 38 | nodePort: null 39 | {{- end }} 40 | - name: actuator 41 | port: {{ .Values.service.port.actuator }} 42 | targetPort: actuator 43 | {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }} 44 | nodePort: {{ .Values.service.nodePort.actuator }} 45 | {{- else if eq .Values.service.type "ClusterIP" }} 46 | nodePort: null 47 | {{- end }} 48 | selector: {{- include "common.labels.matchLabels" . | nindent 4 }} 49 | {{- end }} 50 | -------------------------------------------------------------------------------- /chart/gitlab-service/templates/serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.serviceAccount.create }} 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: {{ template "server.serviceAccountName" . }} 6 | namespace: {{ .Release.Namespace }} 7 | labels: {{- include "common.labels.standard" . | nindent 4 }} 8 | {{- if .Values.commonLabels }} 9 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }} 10 | {{- end }} 11 | {{- if .Values.commonAnnotations }} 12 | annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} 13 | {{- end }} 14 | secrets: 15 | - name: {{ include "common.names.fullname" . }} 16 | {{- end }} 17 | -------------------------------------------------------------------------------- /chart/gitlab-service/templates/tls-secrets.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled }} 2 | {{- if .Values.ingress.secrets }} 3 | {{- range .Values.ingress.secrets }} 4 | apiVersion: v1 5 | kind: Secret 6 | metadata: 7 | name: {{ .name }} 8 | namespace: {{ $.Release.Namespace | quote }} 9 | labels: {{- include "common.labels.standard" $ | nindent 4 }} 10 | {{- if $.Values.commonLabels }} 11 | {{- include "common.tplvalues.render" ( dict "value" $.Values.commonLabels "context" $ ) | nindent 4 }} 12 | {{- end }} 13 | {{- if $.Values.commonAnnotations }} 14 | annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }} 15 | {{- end }} 16 | type: kubernetes.io/tls 17 | data: 18 | tls.crt: {{ .certificate | b64enc }} 19 | tls.key: {{ .key | b64enc }} 20 | --- 21 | {{- end }} 22 | {{- end }} 23 | {{- if and .Values.ingress.tls .Values.ingress.selfSigned }} 24 | {{- $ca := genCA "discourse-ca" 365 }} 25 | {{- $cert := genSignedCert .Values.ingress.hostname nil (list .Values.ingress.hostname) 365 $ca }} 26 | apiVersion: v1 27 | kind: Secret 28 | metadata: 29 | name: {{ printf "%s-tls" .Values.ingress.hostname }} 30 | namespace: {{ .Release.Namespace | quote }} 31 | labels: {{- include "common.labels.standard" . | nindent 4 }} 32 | {{- if .Values.commonLabels }} 33 | {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }} 34 | {{- end }} 35 | {{- if .Values.commonAnnotations }} 36 | annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} 37 | {{- end }} 38 | type: kubernetes.io/tls 39 | data: 40 | tls.crt: {{ $cert.Cert | b64enc | quote }} 41 | tls.key: {{ $cert.Key | b64enc | quote }} 42 | ca.crt: {{ $ca.Cert | b64enc | quote }} 43 | --- 44 | {{- end }} 45 | {{- end }} 46 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM registry.cn-shanghai.aliyuncs.com/c7n/javabase:jdk8u282-b08 2 | RUN mkdir /choerodon && chown -R www-data:www-data /choerodon 3 | COPY --chown=www-data:www-data app.jar /choerodon/gitlab-service.jar 4 | WORKDIR /choerodon 5 | USER 33 6 | CMD java $JAVA_OPTS $SKYWALKING_OPTS -jar /choerodon/gitlab-service.jar -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | gitlab-service 7 | 2.0.1.RELEASE 8 | jar 9 | https://github.com/choerodon/gitlab-service 10 | 11 | 12 | 13 | io.choerodon 14 | choerodon-framework-parent 15 | 2.0.2.RELEASE 16 | 17 | 18 | 19 | app 20 | 21 | 22 | 23 | true 24 | io.choerodon.gitlab.GitlabServiceApplication 25 | 26 | 27 | 28 | 29 | io.choerodon 30 | choerodon-starter-limit 31 | 32 | 33 | org.springframework.data 34 | spring-data-redis 35 | 36 | 37 | 38 | org.hzero.starter 39 | hzero-starter-core 40 | 41 | 42 | fastjson 43 | com.alibaba 44 | 45 | 46 | 47 | 48 | org.hzero.starter 49 | hzero-starter-feign-replay 50 | 51 | 52 | com.fasterxml.jackson.dataformat 53 | jackson-dataformat-yaml 54 | 2.9.0 55 | 56 | 57 | io.choerodon 58 | choerodon-gitlab4j-api 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter-actuator 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-web 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-tomcat 71 | 72 | 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-starter-undertow 77 | 78 | 79 | org.springframework.cloud 80 | spring-cloud-starter-netflix-eureka-client 81 | 82 | 83 | org.springframework.boot 84 | spring-boot-configuration-processor 85 | true 86 | 87 | 88 | 89 | org.springframework.cloud 90 | spring-cloud-config-client 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-starter-aop 95 | 96 | 97 | org.springframework.retry 98 | spring-retry 99 | 100 | 101 | 102 | junit 103 | junit 104 | 4.12 105 | test 106 | 107 | 108 | com.google.code.gson 109 | gson 110 | 2.6.2 111 | 112 | 113 | org.eclipse.jgit 114 | org.eclipse.jgit 115 | 116 | 117 | commons-io 118 | commons-io 119 | 2.4 120 | 121 | 122 | org.springframework.boot 123 | spring-boot-starter-test 124 | test 125 | 126 | 127 | org.toile-libre.libe 128 | curl 129 | LATEST 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/GitlabServiceApplication.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | 9 | import io.choerodon.resource.annoation.EnableChoerodonResourceServer; 10 | 11 | @EnableEurekaClient 12 | @EnableScheduling 13 | @SpringBootApplication 14 | @EnableFeignClients("io.choerodon") 15 | @EnableChoerodonResourceServer 16 | public class GitlabServiceApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(GitlabServiceApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/api/controller/v1/CommitController.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab.api.controller.v1; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import io.choerodon.gitlab.api.vo.CommitVO; 7 | import io.choerodon.gitlab.api.vo.GitlabTransferVO; 8 | 9 | import io.swagger.annotations.ApiOperation; 10 | import io.swagger.annotations.ApiParam; 11 | import org.gitlab4j.api.models.Commit; 12 | import org.gitlab4j.api.models.CommitPayload; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.http.HttpStatus; 15 | import org.springframework.http.ResponseEntity; 16 | import org.springframework.validation.annotation.Validated; 17 | import org.springframework.web.bind.annotation.*; 18 | 19 | import io.choerodon.core.exception.FeignException; 20 | import io.choerodon.gitlab.api.vo.CommitStatuseVO; 21 | import io.choerodon.gitlab.app.service.CommitService; 22 | 23 | import javax.validation.Valid; 24 | 25 | /** 26 | * Created by zzy on 2018/1/14. 27 | */ 28 | @RestController 29 | @RequestMapping(value = "/v1/projects/{projectId}/repository/commits") 30 | public class CommitController { 31 | 32 | @Autowired 33 | private CommitService commitService; 34 | 35 | /** 36 | * 查询某个commit的具体信息 37 | * 38 | * @param projectId 项目 ID 39 | * @param sha COMMIT SHA 40 | * @param userId 用户Id 41 | * @return commit 信息 42 | */ 43 | @ApiOperation(value = "查询某个commit的具体信息") 44 | @GetMapping 45 | public ResponseEntity getPipeline( 46 | @ApiParam(value = "项目id", required = true) 47 | @PathVariable Integer projectId, 48 | @ApiParam(value = "sha", required = true) 49 | @RequestParam String sha, 50 | @ApiParam(value = "userId") 51 | @RequestParam(required = false) Integer userId) { 52 | return Optional.ofNullable(commitService.getCommit(projectId, sha, userId)) 53 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 54 | .orElseThrow(() -> new FeignException("error.commit.get")); 55 | } 56 | 57 | 58 | /** 59 | * 查询某个commit的Statuse 60 | * 61 | * @param projectId 项目 ID 62 | * @param sha COMMIT SHA 63 | * @param userId 用户Id 64 | * @return List 65 | */ 66 | @ApiOperation(value = "查询某个commit的Statuse") 67 | @GetMapping(value = "/statuse") 68 | public ResponseEntity> getCommitStatuse( 69 | @ApiParam(value = "项目id", required = true) 70 | @PathVariable Integer projectId, 71 | @ApiParam(value = "sha", required = true) 72 | @RequestParam String sha, 73 | @ApiParam(value = "userId") 74 | @RequestParam(required = false) Integer userId) { 75 | return Optional.ofNullable(commitService.getCommitStatuse(projectId, sha, userId)) 76 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 77 | .orElseThrow(() -> new FeignException("error.commit.get")); 78 | } 79 | 80 | /** 81 | * 查询某个项目的某个分支的所有commit 82 | * 83 | * @param projectId 项目ID 84 | * @return commit列表 85 | */ 86 | 87 | @ApiOperation(value = "查询某个项目的某个分支的所有commit") 88 | @PostMapping(value = "/branch") 89 | public ResponseEntity> getCommits( 90 | @ApiParam(value = "项目id", required = true) 91 | @PathVariable(value = "projectId") Integer projectId, 92 | @ApiParam(value = "分支名称和创建时间", required = true) 93 | @RequestBody @Validated({GitlabTransferVO.GetCommits.class}) GitlabTransferVO gitlabTransferVO) { 94 | return Optional.ofNullable(commitService.getCommits(projectId, gitlabTransferVO.getBranchName(), gitlabTransferVO.getSince())) 95 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 96 | .orElseThrow(() -> new FeignException("error.commits.get")); 97 | } 98 | 99 | @ApiOperation(value = "查询某个项目的某个分支的所有commit") 100 | @GetMapping(value = "/branch/{ref}") 101 | public ResponseEntity> getCommitsByRef( 102 | @ApiParam(value = "项目id", required = true) 103 | @PathVariable(value = "projectId") Integer projectId, 104 | @ApiParam(value = "分支名称和创建时间", required = true) 105 | @PathVariable(value = "ref") String ref) { 106 | return Optional.ofNullable(commitService.getCommitsByRef(projectId, ref, null)) 107 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 108 | .orElseThrow(() -> new FeignException("error.commits.get")); 109 | } 110 | 111 | 112 | /** 113 | * 查询某个项目的所有commit 114 | * 115 | * @param projectId 项目ID 116 | * @param userId 用户名 117 | * @param page page 118 | * @param size size 119 | * * @return commit列表 120 | */ 121 | 122 | @ApiOperation(value = "查询某个项目的所有commit") 123 | @GetMapping(value = "/project") 124 | public ResponseEntity> listCommits( 125 | @ApiParam(value = "项目id", required = true) 126 | @PathVariable(value = "projectId") Integer projectId, 127 | @ApiParam(value = "page") 128 | @RequestParam Integer page, 129 | @ApiParam(value = "size") 130 | @RequestParam Integer size, 131 | @ApiParam(value = "用户名", required = true) 132 | @RequestParam Integer userId) { 133 | return Optional.ofNullable(commitService.listCommits(projectId, page, size, userId)) 134 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 135 | .orElseThrow(() -> new FeignException("error.commits.get")); 136 | } 137 | 138 | 139 | @PostMapping 140 | @ApiOperation("创建commit,可以批量操作文件") 141 | public ResponseEntity createCommit( 142 | @ApiParam(value = "项目id", required = true) 143 | @PathVariable(value = "projectId") Integer projectId, 144 | @ApiParam(value = "用户名", required = true) 145 | @RequestParam(value = "user_id") Integer userId, 146 | @ApiParam(value = "操作文件相关的信息") 147 | @RequestBody CommitPayload commitPayload) { 148 | commitService.createCommit(projectId, userId, commitPayload); 149 | return new ResponseEntity(HttpStatus.OK); 150 | } 151 | } 152 | 153 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/api/controller/v1/ConfigController.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab.api.controller.v1; 2 | 3 | import io.choerodon.core.exception.CommonException; 4 | import io.choerodon.gitlab.app.service.ConfigService; 5 | import io.swagger.annotations.ApiOperation; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.Optional; 14 | 15 | /** 16 | * @author: trump 17 | * @date: 2019/8/21 14:25 18 | * @description: 19 | */ 20 | @RestController 21 | @RequestMapping(value = "/v1/confings") 22 | public class ConfigController { 23 | 24 | @Autowired 25 | private ConfigService configService; 26 | 27 | /** 28 | * 获取配置文件gitlab组件admin的token 29 | * 30 | * @return token 31 | */ 32 | @ApiOperation(value = "获取配置文件gitlab组件admin的token") 33 | @GetMapping("/get_admin_token") 34 | public ResponseEntity getAdminToken() { 35 | return Optional.ofNullable(configService.getAdminToken()) 36 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 37 | .orElseThrow(() -> new CommonException("error.admin.token.get")); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/api/controller/v1/ExternalProjectController.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab.api.controller.v1; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | 8 | import io.swagger.annotations.ApiOperation; 9 | import io.swagger.annotations.ApiParam; 10 | import org.gitlab4j.api.models.Commit; 11 | import org.gitlab4j.api.models.Project; 12 | import org.gitlab4j.api.models.ProjectHook; 13 | import org.gitlab4j.api.models.RepositoryFile; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.http.HttpStatus; 16 | import org.springframework.http.ResponseEntity; 17 | import org.springframework.web.bind.annotation.*; 18 | 19 | import io.choerodon.core.exception.FeignException; 20 | import io.choerodon.gitlab.api.vo.VariableVO; 21 | import io.choerodon.gitlab.app.service.CommitService; 22 | import io.choerodon.gitlab.app.service.ExternalProjectService; 23 | import io.choerodon.gitlab.app.service.RepositoryService; 24 | import io.choerodon.gitlab.infra.dto.AppExternalConfigDTO; 25 | 26 | /** 27 | * 〈功能简述〉 28 | * 〈〉 29 | * 30 | * @author wanghao 31 | * @since 2021/9/28 21:33 32 | */ 33 | @RestController 34 | @RequestMapping("/v1/external_projects") 35 | public class ExternalProjectController { 36 | 37 | @Autowired 38 | private ExternalProjectService externalProjectService; 39 | @Autowired 40 | private CommitService commitService; 41 | 42 | @Autowired 43 | private RepositoryService repositoryService; 44 | 45 | 46 | @ApiOperation(value = "通过项目id查询项目") 47 | @GetMapping(value = "/query_by_code") 48 | public ResponseEntity queryExternalProjectByCode( 49 | @RequestParam(value = "namespace_code") String namespaceCode, 50 | @RequestParam(value = "project_code") String projectCode, 51 | @ApiParam(value = "认证信息", required = true) 52 | AppExternalConfigDTO appExternalConfigDTO) { 53 | return ResponseEntity.ok(externalProjectService.queryExternalProjectByCode(namespaceCode, projectCode, appExternalConfigDTO)); 54 | } 55 | 56 | /** 57 | * 批量增加/更新项目ci环境变量 58 | * 59 | * @param projectId 项目Id 60 | * @param list variable信息 61 | * @return Map 62 | */ 63 | @ApiOperation(value = " 批量增加/更新项目ci环境变量") 64 | @PutMapping(value = "/{projectId}/variables") 65 | public ResponseEntity>> batchSaveExternalProjectVariable( 66 | @ApiParam(value = "项目ID", required = true) 67 | @PathVariable Integer projectId, 68 | @ApiParam(value = "variable信息", required = true) 69 | @RequestBody @Valid List list, 70 | AppExternalConfigDTO appExternalConfigDTO) { 71 | return Optional.ofNullable(externalProjectService.batchCreateVariable(projectId, list, appExternalConfigDTO)) 72 | .map(target -> new ResponseEntity<>(target, HttpStatus.CREATED)) 73 | .orElseThrow(() -> new FeignException("error.projects.variable.batch.create")); 74 | } 75 | 76 | @ApiOperation(value = "创建ProjectHook对象") 77 | @PostMapping("/hook") 78 | public ResponseEntity create( 79 | @ApiParam(value = "项目ID", required = true) 80 | @RequestParam Integer projectId, 81 | @ApiParam(value = "projectHook对象", required = true) 82 | @RequestBody @Valid ProjectHook projectHook, 83 | AppExternalConfigDTO appExternalConfigDTO) { 84 | return Optional.ofNullable(externalProjectService.createProjectHook(projectId, projectHook, appExternalConfigDTO)) 85 | .map(target -> new ResponseEntity<>(target, HttpStatus.CREATED)) 86 | .orElseThrow(() -> new FeignException("error.projects.add.hook")); 87 | } 88 | 89 | 90 | /** 91 | * 项目下获取file 92 | * 93 | * @param projectId 项目id 94 | * @param commit the commit SHA or branch name 95 | * @param filePath file path 96 | * @return file 97 | */ 98 | @ApiOperation(value = "项目下获取file") 99 | @GetMapping(value = "/{projectId}/repository/{commit}/file") 100 | public ResponseEntity getExternalFile( 101 | @ApiParam(value = "项目id", required = true) @PathVariable Integer projectId, 102 | @ApiParam(value = "commit", required = true) @PathVariable String commit, 103 | @ApiParam(value = "file path", required = true) @RequestParam(value = "file_path") String filePath, 104 | AppExternalConfigDTO appExternalConfigDTO) { 105 | return ResponseEntity.ok(repositoryService.getFile(projectId, commit, filePath, appExternalConfigDTO)); 106 | } 107 | 108 | @ApiOperation(value = "查询某个项目的所有commit") 109 | @GetMapping(value = "/{projectId}/repository/commits/project") 110 | public ResponseEntity> listExternalCommits( 111 | @ApiParam(value = "项目id", required = true) 112 | @PathVariable(value = "projectId") Integer projectId, 113 | @ApiParam(value = "page") 114 | @RequestParam Integer page, 115 | @ApiParam(value = "size") 116 | @RequestParam Integer size, 117 | AppExternalConfigDTO appExternalConfigDTO) { 118 | return Optional.ofNullable(commitService.listExternalCommits(projectId, page, size, appExternalConfigDTO)) 119 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 120 | .orElseThrow(() -> new FeignException("error.commits.get")); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/api/controller/v1/HookController.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab.api.controller.v1; 2 | 3 | import java.util.Optional; 4 | import java.util.List; 5 | 6 | import javax.validation.Valid; 7 | 8 | import io.swagger.annotations.ApiOperation; 9 | import io.swagger.annotations.ApiParam; 10 | import org.gitlab4j.api.models.ProjectHook; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import io.choerodon.core.exception.FeignException; 16 | import io.choerodon.gitlab.app.service.HookService; 17 | 18 | 19 | @RestController 20 | @RequestMapping(value = "/v1/hook") 21 | public class HookController { 22 | 23 | private HookService hookService; 24 | 25 | public HookController(HookService hookService) { 26 | this.hookService = hookService; 27 | } 28 | 29 | /** 30 | * 创建ProjectHook对象 31 | * 32 | * @param projectId 项目id 33 | * @param userId 用户Id 34 | * @param projectHook projectHook对象 35 | * @return ProjectHook 36 | */ 37 | @ApiOperation(value = "创建ProjectHook对象") 38 | @PostMapping 39 | public ResponseEntity create( 40 | @ApiParam(value = "项目ID", required = true) 41 | @RequestParam Integer projectId, 42 | @ApiParam(value = "userId") 43 | @RequestParam(required = false) Integer userId, 44 | @ApiParam(value = "projectHook对象", required = true) 45 | @RequestBody @Valid ProjectHook projectHook) { 46 | return Optional.ofNullable(hookService.createProjectHook(projectId, projectHook, userId)) 47 | .map(target -> new ResponseEntity<>(target, HttpStatus.CREATED)) 48 | .orElseThrow(() -> new FeignException("error.projects.add.hook")); 49 | } 50 | 51 | 52 | /** 53 | * 更新ProjectHook对象 54 | * 55 | * @param projectId 项目id 56 | * @param userId 用户Id 57 | * @param hookId hookId 58 | * @return ProjectHook 59 | */ 60 | @ApiOperation(value = "更新ProjectHook对象") 61 | @PutMapping 62 | public ResponseEntity create( 63 | @ApiParam(value = "项目ID", required = true) 64 | @RequestParam Integer projectId, 65 | @ApiParam(value = "userId") 66 | @RequestParam(required = false) Integer userId, 67 | @ApiParam(value = "hookId", required = true) 68 | @RequestParam Integer hookId) { 69 | return Optional.ofNullable(hookService.updateProjectHook(projectId, hookId, userId)) 70 | .map(target -> new ResponseEntity<>(target, HttpStatus.NO_CONTENT)) 71 | .orElseThrow(() -> new FeignException("error.projects.update.hook")); 72 | } 73 | 74 | 75 | /** 76 | * 获取ProjectHook对象 77 | * 78 | * @param projectId 项目id 79 | * @param userId 用户Id 80 | * @return List 81 | */ 82 | @ApiOperation(value = "获取ProjectHook对象") 83 | @GetMapping 84 | public ResponseEntity> list( 85 | @ApiParam(value = "项目ID", required = true) 86 | @RequestParam Integer projectId, 87 | @ApiParam(value = "userId") 88 | @RequestParam(required = false) Integer userId) { 89 | return Optional.ofNullable(hookService.listProjectHook(projectId, userId)) 90 | .map(target -> new ResponseEntity<>(target, HttpStatus.OK)) 91 | .orElseThrow(() -> new FeignException("error.projects.get.hook")); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/api/controller/v1/JobController.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab.api.controller.v1; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import io.swagger.annotations.ApiOperation; 7 | import io.swagger.annotations.ApiParam; 8 | import org.gitlab4j.api.models.Job; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import io.choerodon.core.exception.FeignException; 14 | import io.choerodon.gitlab.app.service.JobService; 15 | import io.choerodon.gitlab.infra.dto.AppExternalConfigDTO; 16 | 17 | 18 | /** 19 | * Created by zzy on 2018/1/9. 20 | */ 21 | @RestController 22 | @RequestMapping(value = "/v1/projects/{projectId}") 23 | public class JobController { 24 | 25 | private JobService jobService; 26 | 27 | public JobController(JobService jobService) { 28 | this.jobService = jobService; 29 | } 30 | 31 | /** 32 | * 查询项目下pipeline的jobs 33 | * 34 | * @param projectId 项目id 35 | * @param pipelineId 流水线id 36 | * @param userId 用户Id 37 | * @return List 38 | */ 39 | @ApiOperation(value = "查询项目下pipeline的jobs") 40 | @GetMapping(value = "/pipelines/{pipelineId}/jobs") 41 | public ResponseEntity> list( 42 | @ApiParam(value = "项目id", required = true) 43 | @PathVariable Integer projectId, 44 | @ApiParam(value = "pipelineId", required = true) 45 | @PathVariable Integer pipelineId, 46 | @ApiParam(value = "userId") 47 | @RequestParam(required = false) Integer userId, 48 | AppExternalConfigDTO appExternalConfigDTO) { 49 | return Optional.ofNullable(jobService.listJobs(projectId, pipelineId, userId, appExternalConfigDTO)) 50 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 51 | .orElseThrow(() -> new FeignException("error.jobs.get")); 52 | } 53 | 54 | /** 55 | * 查询项目下某个Job的具体信息 56 | * 57 | * @param projectId 项目id 58 | * @param jobId job id 59 | * @return Job 60 | */ 61 | @ApiOperation(value = "查询项目下某个Job的具体信息") 62 | @GetMapping(value = "/jobs/{jobId}") 63 | public ResponseEntity query( 64 | @ApiParam(value = "项目id", required = true) 65 | @PathVariable Integer projectId, 66 | @ApiParam(value = "jobId", required = true) 67 | @PathVariable Integer jobId) { 68 | return Optional.ofNullable(jobService.queryJob(projectId, jobId)) 69 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 70 | .orElseThrow(() -> new FeignException("error.jobs.get")); 71 | } 72 | /** 73 | * 查询某个Job执行日志 74 | * 75 | * @param projectId 项目id 76 | * @param jobId job id 77 | * @return Job 78 | */ 79 | @ApiOperation(value = "查询某个Job执行日志") 80 | @GetMapping(value = "/jobs/{jobId}/trace") 81 | public ResponseEntity queryTrace( 82 | @ApiParam(value = "项目id", required = true) 83 | @PathVariable Integer projectId, 84 | @ApiParam(value = "jobId", required = true) 85 | @PathVariable Integer jobId, 86 | @ApiParam(value = "userId") 87 | @RequestParam(value = "userId", required = false) Integer userId, 88 | AppExternalConfigDTO appExternalConfigDTO) { 89 | return Optional.ofNullable(jobService.queryTrace(projectId, userId, jobId, appExternalConfigDTO)) 90 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 91 | .orElseThrow(() -> new FeignException("error.jobs.get.trace")); 92 | } 93 | 94 | @ApiOperation(value = "重试job") 95 | @PutMapping(value = "/jobs/{jobId}/retry") 96 | public ResponseEntity retry( 97 | @ApiParam(value = "项目id", required = true) 98 | @PathVariable Integer projectId, 99 | @ApiParam(value = "jobId", required = true) 100 | @PathVariable Integer jobId, 101 | @ApiParam(value = "userId") 102 | @RequestParam(value = "userId", required = false) Integer userId, 103 | AppExternalConfigDTO appExternalConfigDTO) { 104 | return Optional.ofNullable(jobService.retry(projectId, userId, jobId, appExternalConfigDTO)) 105 | .map(result -> new ResponseEntity<>(result, HttpStatus.OK)) 106 | .orElseThrow(() -> new FeignException("error.jobs.retry")); 107 | } 108 | 109 | @ApiOperation(value = "执行 manul状态的job") 110 | @PutMapping(value = "/jobs/{jobId}/play") 111 | public ResponseEntity play( 112 | @ApiParam(value = "项目id", required = true) 113 | @PathVariable Integer projectId, 114 | @ApiParam(value = "jobId", required = true) 115 | @PathVariable Integer jobId, 116 | @ApiParam(value = "userId") 117 | @RequestParam(value = "userId") Integer userId) { 118 | return ResponseEntity.ok(jobService.play(projectId, userId, jobId)); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/io/choerodon/gitlab/api/controller/v1/LabelsController.java: -------------------------------------------------------------------------------- 1 | package io.choerodon.gitlab.api.controller.v1; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import io.swagger.annotations.ApiOperation; 7 | import io.swagger.annotations.ApiParam; 8 | import org.gitlab4j.api.models.Label; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import io.choerodon.core.exception.FeignException; 14 | import io.choerodon.gitlab.api.vo.LabelVO; 15 | import io.choerodon.gitlab.app.service.LabelsService; 16 | 17 | @RestController 18 | @RequestMapping(value = "/v1/labels") 19 | public class LabelsController { 20 | 21 | private LabelsService labelsService; 22 | 23 | public LabelsController(LabelsService labelsService) { 24 | this.labelsService = labelsService; 25 | } 26 | 27 | /** 28 | * 查询labels列表 29 | * 30 | * @param projectId 项目id 31 | * @param page 页数 32 | * @param perPage 每页大小 33 | * @return List 34 | */ 35 | @ApiOperation(value = "查询labels列表") 36 | @GetMapping 37 | public ResponseEntity> list( 38 | @ApiParam(value = "项目id", required = true) 39 | @RequestParam Integer projectId, 40 | @ApiParam(value = "页数") 41 | @RequestParam Integer page, 42 | @ApiParam(value = "每页数量") 43 | @RequestParam Integer perPage) { 44 | return Optional.ofNullable(labelsService.listLabels(projectId, page, perPage)) 45 | .map(target -> new ResponseEntity<>(target, HttpStatus.OK)) 46 | .orElseThrow(() -> new FeignException("error.label.query")); 47 | 48 | } 49 | 50 | /** 51 | * 创建labels 52 | * 53 | * @param labelVO label对象 54 | * @return Label 55 | */ 56 | @ApiOperation(value = "创建labels") 57 | @PostMapping 58 | public ResponseEntity