Skip to content

Commit

Permalink
fix set default git variables due to condition check
Browse files Browse the repository at this point in the history
  • Loading branch information
gy2006 committed Mar 5, 2021
1 parent 5b2251c commit e1852ea
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ public abstract class TriggerConverter {
private ObjectMapper objectMapper;

public Optional<GitTrigger> convert(String event, InputStream body) {
Map<String, Function<InputStream, GitTrigger>> mapping = getMapping();
GitTrigger trigger = mapping.get(event).apply(body);
return Optional.ofNullable(trigger);
try {
Map<String, Function<InputStream, GitTrigger>> mapping = getMapping();
GitTrigger trigger = mapping.get(event).apply(body);
return Optional.ofNullable(trigger);
} catch (Exception e) {
return Optional.empty();
}
}

abstract GitSource getGitSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@

package com.flowci.core.trigger.domain;

import static com.flowci.core.trigger.domain.Variables.PR_BASE_REPO_BRANCH;
import static com.flowci.core.trigger.domain.Variables.PR_BASE_REPO_COMMIT;
import static com.flowci.core.trigger.domain.Variables.PR_BASE_REPO_NAME;
import static com.flowci.core.trigger.domain.Variables.PR_HEAD_REPO_BRANCH;
import static com.flowci.core.trigger.domain.Variables.PR_HEAD_REPO_COMMIT;
import static com.flowci.core.trigger.domain.Variables.PR_HEAD_REPO_NAME;
import static com.flowci.core.trigger.domain.Variables.PR_MESSAGE;
import static com.flowci.core.trigger.domain.Variables.PR_NUMBER;
import static com.flowci.core.trigger.domain.Variables.PR_TIME;
import static com.flowci.core.trigger.domain.Variables.PR_TITLE;
import static com.flowci.core.trigger.domain.Variables.PR_URL;

import com.flowci.domain.StringVars;
import com.flowci.util.StringHelper;
import lombok.Getter;
import lombok.Setter;

import static com.flowci.core.trigger.domain.Variables.*;

/**
* @author yang
*/
Expand Down Expand Up @@ -80,6 +70,12 @@ public StringVars toVariableMap() {
map.put(PR_BASE_REPO_NAME, base.repoName);
map.put(PR_BASE_REPO_BRANCH, base.ref);
map.put(PR_BASE_REPO_COMMIT, base.commit);

// set empty string to COMMIT variables
for (String commitVar : COMMIT_VARS) {
map.put(commitVar, StringHelper.EMPTY);
}

return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package com.flowci.core.trigger.domain;

import com.flowci.domain.StringVars;
import java.io.Serializable;

import com.flowci.util.StringHelper;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand Down Expand Up @@ -59,6 +56,12 @@ public StringVars toVariableMap() {
map.put(Variables.GIT_COMMIT_TIME, time);
map.put(Variables.GIT_COMMIT_URL, commitUrl);
map.put(Variables.GIT_COMMIT_NUM, Integer.toString(numOfCommit));

// set empty string to PR variables
for (String prVar : Variables.PR_VARS) {
map.put(prVar, StringHelper.EMPTY);
}

return map;
}

Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/com/flowci/core/trigger/domain/Variables.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package com.flowci.core.trigger.domain;

import com.google.common.collect.ImmutableList;

import java.util.Collection;

public class Variables {

/**
Expand Down Expand Up @@ -46,6 +50,16 @@ public class Variables {

public static final String GIT_COMMIT_NUM = "FLOWCI_GIT_COMMIT_NUM";

public static final Collection<String> COMMIT_VARS = ImmutableList.<String>builder()
.add(GIT_AUTHOR)
.add(GIT_BRANCH)
.add(GIT_COMMIT_ID)
.add(GIT_COMMIT_MESSAGE)
.add(GIT_COMMIT_TIME)
.add(GIT_COMMIT_URL)
.add(GIT_COMMIT_NUM)
.build();

/**
* Variables for git pull request
*/
Expand All @@ -71,6 +85,20 @@ public class Variables {

public static final String PR_BASE_REPO_COMMIT = "FLOWCI_GIT_PR_BASE_REPO_COMMIT";

public static final Collection<String> PR_VARS = ImmutableList.<String>builder()
.add(PR_TITLE)
.add(PR_MESSAGE)
.add(PR_URL)
.add(PR_TIME)
.add(PR_NUMBER)
.add(PR_HEAD_REPO_NAME)
.add(PR_HEAD_REPO_BRANCH)
.add(PR_HEAD_REPO_COMMIT)
.add(PR_BASE_REPO_NAME)
.add(PR_BASE_REPO_BRANCH)
.add(PR_BASE_REPO_COMMIT)
.build();

private Variables() {

}
Expand Down

0 comments on commit e1852ea

Please sign in to comment.