Skip to content

Commit dcd043e

Browse files
committed
Adds the PR Label Bot
1 parent 344d74f commit dcd043e

21 files changed

Lines changed: 766 additions & 2 deletions

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "java",
9+
"name": "Attach",
10+
"request": "attach",
11+
"hostName": "localhost",
12+
"port": "8000"
13+
},
14+
]
15+
}

README.MD

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ It handles:
1212
- IP2ASN
1313
- Profiler Daemon Ingest
1414
- Profiler DB Cleanup
15+
- PR Label Bot
1516

1617
### ACL Cleanup
1718

@@ -39,6 +40,10 @@ This project itself does not provide a data extraction method, but that can be f
3940

4041
Just wipes rows older than 7 days out the profiler table.
4142

43+
### PR Label Bot
44+
45+
Handles labelling PRs on the GitHub based on TM status, assigned type, votes and other stuff.
46+
4247
## Provided Projects
4348

4449
- `TaskDaemon.Core` - Core application which handles running tasks.
@@ -58,7 +63,7 @@ To build, run `mvn package` to generate the JAR file. This will then appear in t
5863

5964
1. Compile the codebase (See `Building`).
6065
2. Copy the jar and the example `config.toml` in the repository root to a running location.
61-
3. Import the `schemas/profiler_schema.sql` schema to your database server.
66+
3. Import the relevant schemas from the `schemas` dir to your database server.
6267
4. Setup the configuration as per section labels.
6368
5. Start the application up, it will now run tasks in the background.
6469

TaskDaemon.Core/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<artifactId>taskdaemon-database-profiler</artifactId>
2828
<version>dev-SNAPSHOT</version>
2929
</dependency>
30+
<dependency>
31+
<groupId>me.aa07.paradise</groupId>
32+
<artifactId>taskdaemon-database-pullrequests</artifactId>
33+
<version>dev-SNAPSHOT</version>
34+
</dependency>
3035
<dependency>
3136
<groupId>org.apache.logging.log4j</groupId>
3237
<artifactId>log4j-core</artifactId>
@@ -55,6 +60,10 @@
5560
<groupId>org.apache.logging.log4j</groupId>
5661
<artifactId>log4j-slf4j2-impl</artifactId>
5762
</dependency>
63+
<dependency>
64+
<groupId>org.kohsuke</groupId>
65+
<artifactId>github-api</artifactId>
66+
</dependency>
5867
</dependencies>
5968

6069
<build>

TaskDaemon.Core/src/me/aa07/paradise/taskdaemon/core/Core.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import me.aa07.paradise.taskdaemon.core.modules.bouncerrestart.BouncerRestartJob;
1010
import me.aa07.paradise.taskdaemon.core.modules.devrank.DevRankJob;
1111
import me.aa07.paradise.taskdaemon.core.modules.ip2asn.Ip2AsnJob;
12+
import me.aa07.paradise.taskdaemon.core.modules.prlabel.PrLabelJob;
1213
import me.aa07.paradise.taskdaemon.core.modules.profilercleanup.ProfilerCleanupJob;
1314
import me.aa07.paradise.taskdaemon.core.modules.profileringest.ProfilerWorker;
1415
import me.aa07.paradise.taskdaemon.core.redis.RedisManager;
@@ -153,12 +154,28 @@ private void setupJobs(Scheduler scheduler, DbCore dbCore, ConfigHolder config,
153154
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 8 * * ?")) // Every day - 8AM
154155
.build();
155156

157+
// PR Label bot
158+
JobDataMap jdm_pullrequests = new JobDataMap();
159+
jdm_pullrequests.put("LOGGER", logger);
160+
jdm_pullrequests.put("DBCORE", dbCore);
161+
jdm_pullrequests.put("TGSCFG", config.tgs);
162+
jdm_pullrequests.put("GITHUBCFG", config.github);
163+
JobDetail jd_pullrequests = JobBuilder.newJob(PrLabelJob.class)
164+
.withIdentity("pullrequests", "pullrequests")
165+
.usingJobData(jdm_pullrequests)
166+
.build();
167+
CronTrigger ct_pullrequests = TriggerBuilder.newTrigger()
168+
.withIdentity("pullrequests", "pullrequests")
169+
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 * * * ?")) // Every hour
170+
.build();
171+
156172
// Schedule all
157173
scheduler.scheduleJob(jd_aclcleanup, ct_aclcleanup);
158174
scheduler.scheduleJob(jd_bouncerrestart, ct_bouncerrestart);
159175
scheduler.scheduleJob(jd_devrank, ct_devrank);
160176
scheduler.scheduleJob(jd_ip2asn, ct_ip2asn);
161177
scheduler.scheduleJob(jd_profilercleanup, ct_profilercleanup);
178+
scheduler.scheduleJob(jd_pullrequests, ct_pullrequests);
162179
}
163180

164181
private void launchAll() {

TaskDaemon.Core/src/me/aa07/paradise/taskdaemon/core/config/ConfigHolder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
public class ConfigHolder {
44
public DatabaseConfig forumsDatabase;
55
public DatabaseConfig gameDatabase;
6+
public GithubConfig github;
67
public Ip2AsnSerivceConfig ip2asn;
78
public PfsenseConfig pfsense;
89
public DatabaseConfig profilerDatabase;
10+
public DatabaseConfig pullRequestsDatabase;
911
public RedisConfig redis;
1012
public TgsConfig tgs;
1113
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package me.aa07.paradise.taskdaemon.core.config;
2+
3+
public class GithubConfig {
4+
public String githubToken;
5+
public long repoId;
6+
public String orgName;
7+
public String reviewTeamSlug;
8+
public String reviewTeamToken;
9+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package me.aa07.paradise.taskdaemon.core.database;
22

33
public enum DatabaseType {
4-
ProfilerDb, GameDb, Forums
4+
GameDb, Forums, ProfilerDb, PullRequests
55
}

TaskDaemon.Core/src/me/aa07/paradise/taskdaemon/core/database/DbCore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private void establishConnections(ConfigHolder config) {
5454
db_types.put(DatabaseType.Forums, config.forumsDatabase);
5555
db_types.put(DatabaseType.GameDb, config.gameDatabase);
5656
db_types.put(DatabaseType.ProfilerDb, config.profilerDatabase);
57+
db_types.put(DatabaseType.PullRequests, config.pullRequestsDatabase);
5758

5859
for (DatabaseType dbtype : db_types.keySet()) {
5960
DatabaseConfig cfg = db_types.get(dbtype);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package me.aa07.paradise.taskdaemon.core.models.prlabel;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import me.aa07.paradise.taskdaemon.database.pullrequests.enums.VotesNewVoteType;
7+
import me.aa07.paradise.taskdaemon.database.pullrequests.enums.VotesNewVotingGroup;
8+
import org.kohsuke.github.GHPullRequest;
9+
10+
public class PullRequest {
11+
public int pullNumber;
12+
public int testmergeRequests;
13+
public String prTypes;
14+
public GHPullRequest prObject;
15+
public HashMap<VotesNewVotingGroup, HashMap<VotesNewVoteType, Integer>> votes;
16+
public ArrayList<String> labels;
17+
18+
public PullRequest() {
19+
votes = new HashMap<VotesNewVotingGroup, HashMap<VotesNewVoteType, Integer>>();
20+
labels = new ArrayList<String>();
21+
}
22+
23+
public int sumTotalApprovals() {
24+
return sumTotalByVoteType(VotesNewVoteType.APPROVE);
25+
}
26+
27+
public int sumTotalObjections() {
28+
return sumTotalByVoteType(VotesNewVoteType.OBJECT);
29+
}
30+
31+
// Safety caching - stops eating API calls
32+
public boolean safeAddLabel(String label) throws IOException {
33+
if (labels.contains(label)) {
34+
return false;
35+
}
36+
37+
labels.add(label);
38+
prObject.addLabels(label);
39+
return true;
40+
}
41+
42+
public boolean safeDelLabel(String label) throws IOException {
43+
if (!labels.contains(label)) {
44+
return false;
45+
}
46+
47+
labels.add(label);
48+
prObject.removeLabels(label);
49+
return true;
50+
}
51+
52+
// Private methods
53+
private int sumTotalByVoteType(VotesNewVoteType voteType) {
54+
int total = 0;
55+
56+
for (VotesNewVotingGroup group : votes.keySet()) {
57+
HashMap<VotesNewVoteType, Integer> vote_map = votes.get(group);
58+
59+
if (vote_map.containsKey(voteType)) {
60+
total += vote_map.get(voteType);
61+
}
62+
}
63+
64+
return total;
65+
}
66+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package me.aa07.paradise.taskdaemon.core.models.tgs;
2+
3+
public class CompileJobResponse {
4+
public RevisionInformation revisionInformation;
5+
}

0 commit comments

Comments
 (0)