Skip to content
Permalink
Browse files
TC Bot config refactored to avoid a number of properties files. Now i…
…t can be configured only using branches.json; Branches scan implemented so it is now possible to see PR-less contributions without starting build. - Fixes #117.

Signed-off-by: Dmitriy Pavlov <dpavlov@apache.org>
  • Loading branch information
dspavlov committed Apr 13, 2019
1 parent 67dcd11 commit 27aa50321c306ec49e6655001ea4fbb3565d3ecd
Showing 42 changed files with 645 additions and 239 deletions.
@@ -1,10 +1,13 @@
{
// Default server (service) code, internal identification
"primaryServerCode": "apache",
"tcServers": [
{
//code of current server
"code": "public",

// reference to another TC server service code to be used instead.
"reference": "apache"
// reference to another TC server to be used instead.
}
],
"jiraServers": [
@@ -21,14 +21,12 @@
import com.google.gson.Gson;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Properties;

import org.apache.ignite.ci.tcbot.conf.BranchesTracked;
import org.apache.ignite.ci.conf.PasswordEncoder;
import org.apache.ignite.ci.tcbot.TcBotSystemProperties;
import org.apache.ignite.ci.tcbot.conf.BranchesTracked;
import org.apache.ignite.ci.util.Base64Util;
import org.apache.ignite.ci.util.ExceptionUtil;
import org.jetbrains.annotations.NotNull;
@@ -56,7 +54,7 @@ public class HelperConfig {
/** JIRA authorization token property name. */
public static final String JIRA_AUTH_TOKEN = "jira.auth_token";

/** JIRA authorization token property name. */
/** Github API url for the project. */
public static final String GIT_API_URL = "git.api_url";

/** JIRA URL to build links to tickets. */
@@ -83,16 +81,11 @@ public static Properties loadAuthProperties(File workDir, String cfgFileName) {

private static Properties loadAuthPropertiesX(File workDir, String cfgFileName) throws IOException {
File file = new File(workDir, cfgFileName);
if (!(file.exists())) {

try (FileWriter writer = new FileWriter(file)) {
writer.write(HOST + "=" + "http://ci.ignite.apache.org/" + ENDL);
writer.write(USERNAME + "=" + ENDL);
writer.write(ENCODED_PASSWORD + "=" + ENDL);
}
throw new IllegalStateException("Please setup parameters for service in config file [" +
file.getCanonicalPath() + "]");
}

Preconditions.checkState(file.exists(),
"Please setup parameters for service in config file [branches.json]. " +
"See conf directory for examples");

return loadProps(file);
}

@@ -136,43 +129,6 @@ public static File resolveWorkDir() {
return ensureDirExist(workDir);
}

/**
* Extract GitHub authorization token from properties.
*
* @param props Properties, where token is placed.
* @return Null or decoded auth token for Github.
*/
@Nullable public static String prepareGithubHttpAuthToken(Properties props) {
String tok = props.getProperty(GITHUB_AUTH_TOKEN);

if (isNullOrEmpty(tok))
return null;

tok = PasswordEncoder.decode(tok);

return tok;
}

/**
* Extract TeamCity authorization token from properties.
*
* @param props Properties, where token is placed.
* @param cfgName Configuration name.
* @return Null or decoded auth token for Github.
*/
@Nullable static String prepareBasicHttpAuthToken(Properties props, String cfgName) {
final String user = getMandatoryProperty(props, USERNAME, cfgName);

String enc = props.getProperty(ENCODED_PASSWORD);

if (isNullOrEmpty(enc))
return null;

String pwd = PasswordEncoder.decode(enc);

return userPwdToToken(user, pwd);
}

@NotNull public static String userPwdToToken(String user, String pwd) {
return Base64Util.encodeUtf8String(user + ":" + pwd);
}
@@ -187,9 +143,10 @@ public static BranchesTracked getTrackedBranches() {
final File workDir = resolveWorkDir();
final File file = new File(workDir, "branches.json");

try(final FileReader json = new FileReader(file)) {
try (FileReader json = new FileReader(file)) {
return new Gson().fromJson(json, BranchesTracked.class);
} catch (IOException e) {
}
catch (IOException e) {
throw ExceptionUtil.propagateException(e);
}
}
@@ -72,14 +72,10 @@ public interface ITeamcity extends ITeamcityConn {
*/
boolean isTeamCityTokenAvailable();


default void setAuthData(String user, String pwd) {
setAuthToken(
Base64Util.encodeUtf8String(user + ":" + pwd));
}

void init(String serverId);

User getUserByUsername(String username);

}
@@ -88,11 +88,6 @@ public class IgnitePersistentTeamcity implements IAnalyticsEnabledTeamcity, ITea
migrations.dataMigration(visasHistStorage.visas());
}

/** {@inheritDoc} */
@Override public void init(String srvId) {
throw new UnsupportedOperationException();
}

/** {@inheritDoc} */
@Override public User getUserByUsername(String username) {
return teamcity.getUserByUsername(username);
@@ -94,7 +94,7 @@ public class IgniteTeamcityConnection implements ITeamcity {
/** Teamcity http connection. */
@Inject private ITeamcityHttpConnection teamcityHttpConn;

@Inject private ITcBotConfig config;
@Inject private ITcBotConfig cfg;

private String srvCode;

@@ -105,15 +105,14 @@ public Executor getExecutor() {
return executor;
}

/** {@inheritDoc} */
@Override public void init(@Nullable String srvCode) {
public void init(@Nullable String srvCode) {
this.srvCode = srvCode;

this.executor = MoreExecutors.directExecutor();
}

public ITcServerConfig config() {
return this.config.getTeamcityConfig(this.srvCode );
return cfg.getTeamcityConfig(this.srvCode);
}

/** {@inheritDoc} */
@@ -21,6 +21,9 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* <b>Note: </b> this cachind annotation ignores object called, may be used only for siglenton-scope classes.
*/
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD)
public @interface GuavaCached {
/**
@@ -17,7 +17,9 @@
package org.apache.ignite.ci.github;

import java.util.Objects;
import org.apache.ignite.ci.db.Persisted;

@Persisted
public class GitHubBranch {
/** Label. */
private String label;
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.github;

import com.google.common.base.Strings;
import java.util.Objects;
import org.apache.ignite.ci.db.Persisted;
import org.jetbrains.annotations.NotNull;

@Persisted
public class GitHubBranchKey implements Comparable<GitHubBranchKey> {
int srvId;
String branchName;

@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
GitHubBranchKey key = (GitHubBranchKey)o;
return srvId == key.srvId &&
Objects.equals(branchName, key.branchName);
}

@Override public int hashCode() {
return Objects.hash(srvId, branchName);
}

public GitHubBranchKey branchName(String name) {
this.branchName = name;

return this;
}

public GitHubBranchKey srvId(int high) {
this.srvId = high;

return this;
}

/** */
public int srvId() {
return srvId;
}

/** */
public String branchName() {
return branchName;
}

/** {@inheritDoc} */
@Override public int compareTo(@NotNull GitHubBranchKey o) {
int compare = Integer.compare(srvId, o.srvId());
if (compare != 0)
return compare;

return Strings.nullToEmpty(branchName).compareTo(o.branchName());
}
}
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.github;

import java.util.Objects;
import org.apache.ignite.ci.db.Persisted;

/**
*
*/
@Persisted
public class GitHubBranchShort {
/** Name. */
String name;
/** Commit. */
GitHubCommit commit;

public String name() {
return name;
}

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
GitHubBranchShort aShort = (GitHubBranchShort)o;
return Objects.equals(name, aShort.name) &&
Objects.equals(commit, aShort.commit);
}

/** {@inheritDoc} */
@Override public int hashCode() {
return Objects.hash(name, commit);
}
}
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.github;

import java.util.Objects;
import org.apache.ignite.ci.db.Persisted;

@Persisted
public class GitHubCommit {
/** Sha of the commit. */
private String sha;

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
GitHubCommit commit = (GitHubCommit)o;
return Objects.equals(sha, commit.sha);
}

/** {@inheritDoc} */
@Override public int hashCode() {
return Objects.hash(sha);
}
}
@@ -18,7 +18,9 @@

import com.google.gson.annotations.SerializedName;
import java.util.Objects;
import org.apache.ignite.ci.db.Persisted;

@Persisted
public class GitHubUser {
@SerializedName("login") private String login;
@SerializedName("avatar_url") private String avatarUrl;

0 comments on commit 27aa503

Please sign in to comment.