Skip to content

Commit 8058a85

Browse files
authored
Add files via upload
1 parent f340a0a commit 8058a85

File tree

18 files changed

+672
-0
lines changed

18 files changed

+672
-0
lines changed

dependency-reduced-pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.example</groupId>
5+
<artifactId>Github-Follower-Bot</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<artifactId>maven-jar-plugin</artifactId>
11+
<version>3.2.0</version>
12+
<configuration>
13+
<archive>
14+
<manifestEntries>
15+
<Main-Class>com.example.GitHubBot</Main-Class>
16+
</manifestEntries>
17+
</archive>
18+
</configuration>
19+
</plugin>
20+
<plugin>
21+
<artifactId>maven-shade-plugin</artifactId>
22+
<version>3.6.0</version>
23+
<executions>
24+
<execution>
25+
<phase>package</phase>
26+
<goals>
27+
<goal>shade</goal>
28+
</goals>
29+
<configuration>
30+
<filters>
31+
<filter>
32+
<artifact>*:*</artifact>
33+
<excludes>
34+
<exclude>META-INF/*.SF</exclude>
35+
<exclude>META-INF/*.DSA</exclude>
36+
<exclude>META-INF/*.RSA</exclude>
37+
</excludes>
38+
</filter>
39+
</filters>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
<properties>
47+
<maven.compiler.target>22</maven.compiler.target>
48+
<maven.compiler.source>22</maven.compiler.source>
49+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
50+
</properties>
51+
</project>
76.7 KB
Binary file not shown.

libs/jackson-core-2.17.2.jar

568 KB
Binary file not shown.

libs/jackson-databind-2.17.2.jar

1.57 MB
Binary file not shown.

manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Main-Class: com.example.GitHubBot

operations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ }

out/com/example/GitHubBot.class

18.1 KB
Binary file not shown.

pom.xml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<build>
8+
<plugins>
9+
<!-- Existing plugins -->
10+
<plugin>
11+
<groupId>org.apache.maven.plugins</groupId>
12+
<artifactId>maven-jar-plugin</artifactId>
13+
<version>3.2.0</version>
14+
<configuration>
15+
<archive>
16+
<manifestEntries>
17+
<Main-Class>com.example.GitHubBot</Main-Class> <!-- Replace with your main class -->
18+
</manifestEntries>
19+
</archive>
20+
</configuration>
21+
</plugin>
22+
<plugin>
23+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-shade-plugin -->
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-shade-plugin</artifactId>
26+
<version>3.6.0</version>
27+
28+
<executions>
29+
<execution>
30+
<phase>package</phase>
31+
<goals>
32+
<goal>shade</goal>
33+
</goals>
34+
<configuration>
35+
<filters>
36+
<filter>
37+
<artifact>*:*</artifact>
38+
<excludes>
39+
<exclude>META-INF/*.SF</exclude>
40+
<exclude>META-INF/*.DSA</exclude>
41+
<exclude>META-INF/*.RSA</exclude>
42+
</excludes>
43+
</filter>
44+
</filters>
45+
</configuration>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
52+
53+
<groupId>com.example</groupId>
54+
<artifactId>Github-Follower-Bot</artifactId>
55+
<version>1.0-SNAPSHOT</version>
56+
57+
<properties>
58+
<maven.compiler.source>22</maven.compiler.source>
59+
<maven.compiler.target>22</maven.compiler.target>
60+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
61+
</properties>
62+
63+
<dependencies>
64+
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5 -->
65+
<dependency>
66+
<groupId>org.apache.httpcomponents.client5</groupId>
67+
<artifactId>httpclient5</artifactId>
68+
<version>5.3</version>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>org.openjfx</groupId>
73+
<artifactId>javafx-controls</artifactId>
74+
<version>17.0.1</version>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>com.fasterxml.jackson.core</groupId>
79+
<artifactId>jackson-databind</artifactId>
80+
<version>2.12.3</version>
81+
</dependency>
82+
</dependencies>
83+
84+
85+
</project>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.example;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import java.util.Scanner;
8+
import java.util.concurrent.*;
9+
import java.util.concurrent.atomic.AtomicBoolean;
10+
import static com.example.Utils.*;
11+
12+
public class GitHubBot {
13+
private static final AtomicBoolean stopFlag = new AtomicBoolean(false);
14+
static final AtomicBoolean rateLimitExceeded = new AtomicBoolean(false);
15+
static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
16+
17+
public static void main(String[] args) {
18+
if (GITHUB_TOKEN == null || GITHUB_TOKEN.isEmpty()) {
19+
System.err.println(RED + "GitHub token is not set. Please set the GITHUB_TOKEN environment variable." + RESET);
20+
return;
21+
}
22+
23+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
24+
stopFlag.set(true);
25+
System.out.println(YELLOW + "\nShutdown signal received. Stopping the bot..." + RESET);
26+
}));
27+
28+
printRateLimit();
29+
displayMenu();
30+
}
31+
32+
private static void displayMenu() {
33+
System.out.println(BLUE + "GitHub Bot Interface Panel" + RESET);
34+
System.out.println("1- Start the bot");
35+
System.out.println("2- Undo actions or operations");
36+
37+
Scanner scanner = new Scanner(System.in);
38+
System.out.print("Choose an option: ");
39+
int choice = scanner.nextInt();
40+
41+
switch (choice) {
42+
case 1:
43+
System.out.println(BLUE + "Starting GitHub bot..." + RESET);
44+
scheduleTask(0);
45+
break;
46+
case 2:
47+
System.out.println(YELLOW + "Undoing actions or operations..." + RESET);
48+
undoOperations();
49+
break;
50+
default:
51+
System.err.println(RED + "Invalid choice. Exiting..." + RESET);
52+
break;
53+
}
54+
}
55+
56+
private static void scheduleTask(long delay) {
57+
scheduler.schedule(() -> {
58+
List<JsonNode> repositories = fetchAllRepositories();
59+
System.out.println("Fetched " + PURPLE + repositories.size() + RESET + " repositories.");
60+
61+
List<CompletableFuture<Void>> futures = new ArrayList<>();
62+
for (JsonNode repo : repositories) {
63+
if (stopFlag.get() || rateLimitExceeded.get()) break;
64+
65+
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> processRepository(repo), executorService);
66+
futures.add(future);
67+
68+
try {
69+
// Introduce delay between operations to avoid being flagged as spam
70+
Thread.sleep(5000); // 5 seconds delay
71+
} catch (InterruptedException e) {
72+
Thread.currentThread().interrupt();
73+
}
74+
}
75+
76+
CompletableFuture<Void> allOf = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
77+
try {
78+
allOf.get();
79+
} catch (InterruptedException | ExecutionException e) {
80+
logError("Error waiting for tasks to complete", e);
81+
}
82+
83+
if (rateLimitExceeded.get()) {
84+
System.out.println(YELLOW + "Rescheduling all follow operations after 1 hour due to rate limit exceeded..." + RESET);
85+
scheduleTask(3600); // Reschedule after 1 hour
86+
} else {
87+
shutdownExecutorServices();
88+
}
89+
}, delay, TimeUnit.SECONDS);
90+
}
91+
}

0 commit comments

Comments
 (0)