-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathGitHubIntegration.java
More file actions
39 lines (33 loc) · 1.35 KB
/
Copy pathGitHubIntegration.java
File metadata and controls
39 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.pathvisio.gui;
import org.kohsuke.github.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class GitHubIntegration {
private GitHub github;
public GitHubIntegration(String token) throws Exception {
github = GitHub.connectUsingOAuth(token);
}
public GitHubIntegration() throws Exception {
// Load token from a properties file
String token = loadTokenFromProperties();
if (token == null || token.isEmpty()) {
throw new IllegalStateException("GitHub token not found in config.properties");
}
github = GitHub.connectUsingOAuth(token);
}
private String loadTokenFromProperties() {
Properties properties = new Properties();
try (FileInputStream fis = new FileInputStream("config.properties")) {
properties.load(fis);
return properties.getProperty("github.token");
} catch (IOException e) {
System.err.println("Failed to load GitHub token from config.properties: " + e.getMessage());
return null;
}
}
public void saveToGitHub(String repoName, String filePath, String content, String commitMessage) throws Exception {
GHRepository repo = github.getRepository(repoName);
repo.createContent(content, commitMessage, filePath);
}
}