Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: allow create tag with branch name #184

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,16 @@ private Map<String, Object> createTag(Map<String, Object> in, String gitHubUri)
String gitHubTagMessage = assertString(in, GITHUB_TAGMESSAGE);
String gitHubTaggerUID = assertString(in, GITHUB_TAGGERUID);
String gitHubTaggerEMAIL = assertString(in, GITHUB_TAGGEREMAIL);
String gitHubBranchSHA = assertString(in, GITHUB_COMMIT_SHA);
String gitHubBranchSHA = getString(in, GITHUB_COMMIT_SHA);
String githubBranch = getString(in, GITHUB_BRANCH);

if (isBlank(gitHubBranchSHA) && isBlank(githubBranch)) {
throw new IllegalArgumentException("Invalid task input parameters: " + GITHUB_COMMIT_SHA + " or " + GITHUB_BRANCH + " is required");
}

if (isBlank(gitHubBranchSHA)) {
gitHubBranchSHA = getLatestSHAValue(in, gitHubUri);
}

//Initiate the client
GitHubClient client = createClient(gitHubUri);
Expand Down Expand Up @@ -908,6 +917,10 @@ private Map<String, Object> deleteRepo(Map<String, Object> in, String gitHubUri)
}

private static Map<String, Object> getLatestSHA(Map<String, Object> in, String gitHubUri) {
return Map.of("latestCommitSHA", getLatestSHAValue(in, gitHubUri));
}

private static String getLatestSHAValue(Map<String, Object> in, String gitHubUri) {
String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN);
String gitHubOrgName = assertString(in, GITHUB_ORGNAME);
String gitHubRepoName = assertString(in, GITHUB_REPONAME);
Expand All @@ -933,7 +946,7 @@ private static Map<String, Object> getLatestSHA(Map<String, Object> in, String g

log.info("Latest commit SHA: '{}'", latestCommitSHA);

return Collections.singletonMap("latestCommitSHA", latestCommitSHA);
return latestCommitSHA;
} catch (Exception e) {
throw new RuntimeException("Error occurred while getting latest commit SHA: " + e.getMessage());
}
Expand Down Expand Up @@ -1107,6 +1120,10 @@ private static Map<String, Object> makeResult(Object data) {
return m;
}

private static boolean isBlank(String str) {
return str == null || str.isBlank();
}

static GitHubClient createClient(String rawUrl) {
String host;
int port;
Expand Down