Skip to content

Commit

Permalink
github: allow create tag with branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
brig committed Jan 28, 2025
1 parent 834f5b8 commit 55f2232
Showing 1 changed file with 19 additions and 2 deletions.
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 Collections.singletonMap("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

0 comments on commit 55f2232

Please sign in to comment.