Skip to content
Permalink
Browse files
PR apply script added; code style changes applied; version updated
  • Loading branch information
dspavlov committed Aug 17, 2018
1 parent ab1216c commit 7f89dabfcc430c52bbe0af97b1133af6eec7840c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 34 deletions.
@@ -22,14 +22,17 @@
import java.util.stream.Stream;

/**
* Created by Дмитрий on 05.11.2017.
* One tracked branch, probably on several servers
*/
public class BranchTracked {
/** ID for internal REST and for */
public String id;

public List<ChainAtServerTracked> chains = new ArrayList<>();

/**
* @return internal identifier of the branch.
*/
public String getId() {
return id;
}
@@ -24,11 +24,15 @@
import java.util.stream.Collectors;

/**
* Created by Дмитрий on 05.11.2017.
* Config file for tracked branches.
*/
public class BranchesTracked {
public List<BranchTracked> branches = new ArrayList<>();
/** Branches. */
private List<BranchTracked> branches = new ArrayList<>();

/**
* @return list of internal identifiers of branch.
*/
public List<String> getIds() {
return branches.stream().map(BranchTracked::getId).collect(Collectors.toList());
}
@@ -33,13 +33,12 @@
import static javax.xml.bind.DatatypeConverter.printHexBinary;

/**
* Created by Дмитрий on 05.11.2017.
* Encoding utility to avoid simply readable password in config.
*/
public class PasswordEncoder {

public static final int PREF_LEN = 16;
public static final int POSTF_LEN = 16;
public static final char CHAR = 'A';
private static final int PREF_LEN = 16;
private static final int POSTF_LEN = 16;
private static final char CHAR = 'A';

public static String decode(String encPass) {
final String clearBlk = printHexBinary(d(parseHexBinary(encPass)));
@@ -44,7 +44,7 @@ public static void main(String[] args) {

public static void sendEmail(String to, String subject, String html, String plainText) {
Properties cfgProps = HelperConfig.loadEmailSettings();
String username = HelperConfig.getMandatoryProperty(cfgProps, HelperConfig.USERNAME, HelperConfig. MAIL_PROPS);
String from = HelperConfig.getMandatoryProperty(cfgProps, HelperConfig.USERNAME, HelperConfig. MAIL_PROPS);
String enc = HelperConfig.getMandatoryProperty(cfgProps, HelperConfig.ENCODED_PASSWORD, HelperConfig.MAIL_PROPS);

String pwd = PasswordEncoder.decode(enc);
@@ -57,14 +57,13 @@ public static void sendEmail(String to, String subject, String html, String plai
props.put("mail.smtp.port", "465");

// Sender's email ID needs to be mentioned
String from = username;
// Setup mail getOrCreateCreds
// Get the default Session object.

Session ses = Session.getInstance(props,
new Authenticator() {
@Override protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, pwd);
return new PasswordAuthentication(from, pwd);
}
});
try {
@@ -28,53 +28,51 @@
import java.io.IOException;
import java.util.Properties;

/**
*
*/
public class SlackSender {
public static void main(String[] args) throws IOException {
String addr = "dpavlov";
sendMessage(addr, "hi im a bot " +
"<http://localhost:8080|app>");
}

public static boolean sendMessage(String addr, String message) throws IOException {
public static boolean sendMessage(String addr, String msg) throws IOException {
Properties cfgProps = HelperConfig.loadEmailSettings();
String authTok = HelperConfig.getMandatoryProperty(cfgProps, HelperConfig.SLACK_AUTH_TOKEN, HelperConfig. MAIL_PROPS);

SlackSession session = SlackSessionFactory.createWebSocketSlackSession(authTok);
session.connect();
SlackSession ses = SlackSessionFactory.createWebSocketSlackSession(authTok);

ses.connect();

try {
if(addr.startsWith("#")) {
String channel = addr.substring(1);
String ch = addr.substring(1);

SlackChannel slackChannel = session.findChannelByName(channel);
SlackChannel slackCh = ses.findChannelByName(ch);

if (slackChannel == null) {
System.err.println("Failed to find channel [" + addr + "]: Notification not send [" + message + "]");
if (slackCh == null) {
System.err.println("Failed to find channel [" + addr + "]: Notification not send [" + msg + "]");

return false;
}

SlackMessageHandle<SlackMessageReply> handle = session.sendMessage(slackChannel, message);
SlackMessageHandle<SlackMessageReply> handle = ses.sendMessage(slackCh, msg);

System.out.println("Message to channel " + addr + " " + message + "; acked: " + handle.isAcked());
System.out.println("Message to channel " + addr + " " + msg + "; acked: " + handle.isAcked());
}
else {
SlackUser user = session.findUserByUserName(addr); //make sure bot is a member of the user.
SlackUser user = ses.findUserByUserName(addr); //make sure bot is a member of the user.

if (user == null) {
System.err.println("Failed to find user [" + addr + "]: Notification not send [" + message + "]");
System.err.println("Failed to find user [" + addr + "]: Notification not send [" + msg + "]");

return false;
}

SlackMessageHandle<SlackMessageReply> handle = session.sendMessageToUser(user, message, null);
SlackMessageHandle<SlackMessageReply> handle = ses.sendMessageToUser(user, msg, null);

System.out.println("Message to user " + addr + " " + message + "; acked: " + handle.isAcked());
System.out.println("Message to user " + addr + " " + msg + "; acked: " + handle.isAcked());

}
}
finally {
session.disconnect();
ses.disconnect();
}

return true;
@@ -19,7 +19,7 @@

@SuppressWarnings("PublicField") public class Version {
/** TC Helper Version. */
public String version = "20180813";
public String version = "20180817";

/** Ignite version. */
public String ignVer;
@@ -28,8 +28,7 @@
public String ignVerFull;

/** TC Helper Source web. */
public String srcWebUrl = "https://github.com/dspavlov/ignite-teamcity-helper";

public String srcWebUrl = "https://github.com/ignite/ignite-teamcity-bot";

public Version() {}
}
@@ -0,0 +1,24 @@
@echo off
set PR_BRANCH_NAME=pr%1
set TARGET_BRANCH=master

set APACHE_GIT=https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
set GITHUB_MIRROR=https://github.com/apache/ignite-teamcity-bot

git fetch %GITHUB_MIRROR% pull/%1/head:%PR_BRANCH_NAME%

rem jump to branch to show data
git checkout %PR_BRANCH_NAME%

rem show author
git --no-pager show -s
rem removed from command --format="%%aN <%%aE>" HEAD

rem show message
echo "
git log -1 --pretty=%%B
echo - Fixes #%1."
rem removed from command --pretty=%%B

git checkout %TARGET_BRANCH%
git merge --squash %PR_BRANCH_NAME%

0 comments on commit 7f89dab

Please sign in to comment.