Skip to content

Commit

Permalink
Remove # from channel name when uploading file (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored May 7, 2024
1 parent 41060f5 commit bacb598
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private String convertChannelNameToId(String channelName, CloseableHttpClient cl
JSONArray channelsArray = result.getJSONArray("channels");
for (int i = 0; i < channelsArray.length(); i++) {
JSONObject channel = channelsArray.getJSONObject(i);
if (channel.getString("name").equals(channelName)) {
if (channel.getString("name").equals(cleanChannelName(channelName))) {
return channel.getString("id");
}
}
Expand All @@ -213,6 +213,13 @@ private String convertChannelNameToId(String channelName, CloseableHttpClient cl
return null;
}

private static String cleanChannelName(String channelName) {
if (channelName.startsWith("#")) {
return channelName.substring(1);
}
return channelName;

Check warning on line 220 in src/main/java/jenkins/plugins/slack/pipeline/SlackUploadFileRunner.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 201-220 are not covered by tests
}

private boolean uploadFile(String uploadUrl, MultipartEntityBuilder multipartEntityBuilder, CloseableHttpClient client) throws IOException {
HttpUriRequest request = RequestBuilder
.post(uploadUrl)
Expand Down

0 comments on commit bacb598

Please sign in to comment.