Skip to content

Commit 0953edf

Browse files
committed
Add ability to preservce gitlab projects with DO_NOT_DELTE tag
1 parent 07947b1 commit 0953edf

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/main/java/com/redhat/labs/omp/models/gitlab/Project.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.redhat.labs.omp.models.gitlab;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45
import java.util.Map;
56

@@ -18,6 +19,8 @@
1819
@AllArgsConstructor
1920
public class Project {
2021

22+
private static final String DO_NOT_DELETE = "DO_NOT_DELETE";
23+
2124
@JsonbProperty("id")
2225
private Integer id;
2326
@NotBlank
@@ -143,4 +146,14 @@ public static Project from(ProjectSearchResults result) {
143146

144147
}
145148

149+
public void preserve() {
150+
if(tagList == null) {
151+
tagList = new ArrayList<String>();
152+
}
153+
154+
if(!tagList.contains(DO_NOT_DELETE)) {
155+
tagList.add(DO_NOT_DELETE);
156+
}
157+
}
158+
146159
}

src/main/java/com/redhat/labs/omp/service/ProjectService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.enterprise.context.ApplicationScoped;
77
import javax.inject.Inject;
88

9+
import org.eclipse.microprofile.config.inject.ConfigProperty;
910
import org.eclipse.microprofile.rest.client.inject.RestClient;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -23,6 +24,9 @@ public class ProjectService {
2324
@RestClient
2425
GitLabService gitLabService;
2526

27+
@ConfigProperty(name = "engagements.do.not.delete")
28+
boolean doNotDelete;
29+
2630
// get a project
2731
public Optional<Project> getProjectByName(Integer namespaceId, String name)
2832
throws UnexpectedGitLabResponseException {
@@ -53,7 +57,7 @@ public List<ProjectSearchResults> getAllProjectsByNane(String name) {
5357
public List<Project> getProjectsByGroup(int groupId, Boolean includeSubgroups) {
5458
List<Project> projects = gitLabService.getProjectsbyGroup(groupId, includeSubgroups);
5559

56-
if(LOGGER.isDebugEnabled()) {
60+
if(LOGGER.isTraceEnabled()) {
5761
LOGGER.trace("project count group id({}) {}", groupId, projects.size());
5862
projects.stream().forEach(project -> LOGGER.debug("Group {} Project {}", groupId, project.getName()));
5963
}
@@ -80,6 +84,12 @@ public Optional<Project> createProject(Project project) {
8084

8185
Optional<Project> optional = Optional.empty();
8286

87+
if(doNotDelete) {
88+
project.preserve();
89+
}
90+
91+
LOGGER.debug("create project " + project);
92+
8393
// try to create project
8494
Project createdProject = gitLabService.createProject(project);
8595
if (null != createdProject) {

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ config.file=${CONFIG_FILE:schema/config.yml}
3030

3131
# engagements
3232
engagements.repository.id=${ENGAGEMENTS_REPOSITORY_ID:2}
33+
engagements.do.not.delete=${ENGAGEMENTS_PRESERVE:false}
3334

3435
# version
3536
git.commit=${GIT_API_GIT_COMMIT:not.set}

0 commit comments

Comments
 (0)