Skip to content

Commit

Permalink
move crs event types to common
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBredl committed Jul 26, 2024
1 parent eeb0582 commit cdb94b3
Showing 1 changed file with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package de.unistuttgart.iste.meitrex.scrumgame.crs;

import de.unistuttgart.iste.meitrex.generated.dto.*;

import java.util.ArrayList;
import java.util.List;

/**
* Event types for Code Repository Systems.
*/
public class CrsEventTypes {

private static final List<DefaultFieldSchemaDefinition> DEFAULT_FIELDS = List.of(
DefaultFieldSchemaDefinition.builder()
.setName("repositoryName")
.setType(AllowedDataType.STRING)
.setDescription("The name of the repository.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("repositoryUrl")
.setType(AllowedDataType.STRING)
.setDescription("The URL of the repository.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("vcsUsername")
.setType(AllowedDataType.STRING)
.setDescription("The Vcs username.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("vcsAvatarUrl")
.setType(AllowedDataType.STRING)
.setDescription("The URL of the Vcs avatar.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("vcsProfileUrl")
.setType(AllowedDataType.STRING)
.setDescription("The URL of the Vcs profile.")
.setRequired(false)
.build());

private static List<DefaultFieldSchemaDefinition> defaultFieldsAnd(DefaultFieldSchemaDefinition... additionalFields) {
List<DefaultFieldSchemaDefinition> fields = new ArrayList<>(DEFAULT_FIELDS);
fields.addAll(List.of(additionalFields));
return fields;
}

private static final List<DefaultFieldSchemaDefinition> PULL_REQUEST_FIELDS = defaultFieldsAnd(
DefaultFieldSchemaDefinition.builder()
.setName("pullRequestTitle")
.setType(AllowedDataType.STRING)
.setDescription("The title of the pull request.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("pullRequestUrl")
.setType(AllowedDataType.STRING)
.setDescription("The URL of the pull request.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("commitCount")
.setType(AllowedDataType.INTEGER)
.setDescription("The number of commits.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("additions")
.setType(AllowedDataType.INTEGER)
.setDescription("The number of additions.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("deletions")
.setType(AllowedDataType.INTEGER)
.setDescription("The number of deletions.")
.setRequired(false)
.build()
);

public static final EventType PUSH = DefaultEventType.builder()
.setIdentifier("PUSH")
.setDescription("A push event.")
.setDefaultVisibility(EventVisibility.PUBLIC)
.setMessageTemplate("pushed to branch ${branch} with ${commitCount} commits.")
.setEventSchema(DefaultSchemaDefinition.builder()
.setFields(
defaultFieldsAnd(
DefaultFieldSchemaDefinition.builder()
.setName("branch")
.setType(AllowedDataType.STRING)
.setDescription("The name of the branch.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("branchUrl")
.setType(AllowedDataType.STRING)
.setDescription("The URL of the branch.")
.setRequired(false)
.build(),
DefaultFieldSchemaDefinition.builder()
.setName("commitCount")
.setType(AllowedDataType.INTEGER)
.setDescription("The number of commits.")
.setRequired(false)
.build()))
.build())
.build();

public static final EventType OPEN_PULL_REQUEST = DefaultEventType.builder()
.setIdentifier("OPEN_PULL_REQUEST")
.setDescription("An open pull request event.")
.setMessageTemplate(
"opened the pull request ${pullRequestTitle} with ${commitCount} commits in the repository ${repositoryName}.")
.setDefaultVisibility(EventVisibility.PUBLIC)
.setEventSchema(DefaultSchemaDefinition.builder()
.setFields(PULL_REQUEST_FIELDS)
.build())
.build();

public static final EventType CLOSE_PULL_REQUEST = DefaultEventType.builder()
.setIdentifier("CLOSE_PULL_REQUEST")
.setDescription("A close pull request event.")
.setMessageTemplate(
"closed the pull request ${pullRequestTitle} with ${commitCount} commits in the repository ${repositoryName}.")
.setDefaultVisibility(EventVisibility.PUBLIC)
.setEventSchema(DefaultSchemaDefinition.builder()
.setFields(PULL_REQUEST_FIELDS)
.build())
.build();

public static final EventType REVIEW_ACCEPT = DefaultEventType.builder()
.setIdentifier("REVIEW_ACCEPT")
.setDescription("A review submitted event.")
.setDefaultVisibility(EventVisibility.PUBLIC)
.setMessageTemplate("accepted the pull request ${pullRequestTitle}.")
.setEventSchema(DefaultSchemaDefinition.builder()
.setFields(PULL_REQUEST_FIELDS)
.build())
.build();

public static final EventType REVIEW_CHANGE_REQUEST = DefaultEventType.builder()
.setIdentifier("REVIEW_CHANGE_REQUEST")
.setDescription("A review change request event.")
.setMessageTemplate("requested changes for the pull request ${pullRequestTitle}.")
.setDefaultVisibility(EventVisibility.PUBLIC)
.setEventSchema(DefaultSchemaDefinition.builder()
.setFields(PULL_REQUEST_FIELDS)
.build())
.build();

public static List<EventType> allEventTypes() {
return List.of(PUSH, OPEN_PULL_REQUEST, CLOSE_PULL_REQUEST, REVIEW_ACCEPT, REVIEW_CHANGE_REQUEST);
}
}

0 comments on commit cdb94b3

Please sign in to comment.