2019-04-10 08:59:42 +02:00
|
|
|
const ConfigParser = require("configparser");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
export class RepositoryInformationManager {
|
|
|
|
public token(rootPath: string | undefined) {
|
|
|
|
const config = new ConfigParser();
|
|
|
|
config.read(path.join(rootPath as string, "/.gitea/config.ini"));
|
|
|
|
return config.get("PRIVATE", "token");
|
|
|
|
}
|
|
|
|
public repoApiUrl(rootPath: string | undefined) {
|
|
|
|
const config = new ConfigParser();
|
|
|
|
config.read(rootPath + "/.gitea/config.ini");
|
|
|
|
const domain = config.get("REPO", "domain");
|
|
|
|
const repo_owner = config.get("REPO", "repo_owner");
|
|
|
|
const repo_name = config.get("REPO", "repo_name");
|
2019-04-10 13:45:47 +02:00
|
|
|
const ssl = config.get("REPO", "ssl");
|
|
|
|
const prefix = ssl ? "https" : "http";
|
|
|
|
return prefix + "://" + domain + "/api/v1/repos/" + repo_owner + "/" + repo_name + "/issues";
|
2019-04-10 08:59:42 +02:00
|
|
|
}
|
|
|
|
public saveRepoInformation(rootPath: string | undefined, repoInformations: any) {
|
|
|
|
const file_path = path.join(rootPath as string, ".gitea/config.ini");
|
|
|
|
const config = new ConfigParser();
|
|
|
|
config.addSection("PRIVATE");
|
|
|
|
config.addSection("REPO");
|
|
|
|
config.set("PRIVATE", "token", repoInformations.token);
|
|
|
|
config.set("REPO", "domain", repoInformations.domain);
|
|
|
|
config.set("REPO", "repo_owner", repoInformations.repo_owner);
|
|
|
|
config.set("REPO", "repo_name", repoInformations.repo_name);
|
2019-04-10 13:45:47 +02:00
|
|
|
config.set("REPO", "ssl", true);
|
|
|
|
config.write(file_path, true);
|
2019-04-10 08:59:42 +02:00
|
|
|
}
|
|
|
|
}
|