Skip to content

Commit 98b931e

Browse files
committed
Change GithubClient to use settings directly
1 parent 8843ae0 commit 98b931e

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/github/client.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { requestUrl } from "obsidian";
22
import Logger from "src/logger";
3+
import { GitHubSyncSettings } from "src/settings/settings";
34

45
export type RepoContent = {
56
files: { [key: string]: GetTreeResponseItem };
@@ -40,17 +41,14 @@ export type BlobFile = {
4041

4142
export default class GithubClient {
4243
constructor(
43-
private token: string,
44-
private owner: string,
45-
private repo: string,
46-
private branch: string,
44+
private settings: GitHubSyncSettings,
4745
private logger: Logger,
4846
) {}
4947

5048
headers() {
5149
return {
5250
Accept: "application/vnd.github+json",
53-
Authorization: `Bearer ${this.token}`,
51+
Authorization: `Bearer ${this.settings.githubToken}`,
5452
"X-GitHub-Api-Version": "2022-11-28",
5553
};
5654
}
@@ -62,7 +60,7 @@ export default class GithubClient {
6260
*/
6361
async getRepoContent(): Promise<RepoContent> {
6462
const res = await requestUrl({
65-
url: `https://api.github.com/repos/${this.owner}/${this.repo}/git/trees/${this.branch}?recursive=1`,
63+
url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/git/trees/${this.settings.githubBranch}?recursive=1`,
6664
headers: this.headers(),
6765
throw: false,
6866
});
@@ -84,7 +82,7 @@ export default class GithubClient {
8482

8583
async createTree(tree: { tree: NewTreeRequestItem[]; base_tree: string }) {
8684
const res = await requestUrl({
87-
url: `https://api.github.com/repos/${this.owner}/${this.repo}/git/trees`,
85+
url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/git/trees`,
8886
headers: this.headers(),
8987
method: "POST",
9088
body: JSON.stringify(tree),
@@ -99,7 +97,7 @@ export default class GithubClient {
9997

10098
async createCommit(message: string, treeSha: string, parent: string) {
10199
const res = await requestUrl({
102-
url: `https://api.github.com/repos/${this.owner}/${this.repo}/git/commits`,
100+
url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/git/commits`,
103101
headers: this.headers(),
104102
method: "POST",
105103
body: JSON.stringify({
@@ -118,7 +116,7 @@ export default class GithubClient {
118116

119117
async getBranchHeadSha() {
120118
const res = await requestUrl({
121-
url: `https://api.github.com/repos/${this.owner}/${this.repo}/git/refs/heads/${this.branch}`,
119+
url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/git/refs/heads/${this.settings.githubBranch}`,
122120
headers: this.headers(),
123121
throw: false,
124122
});
@@ -131,7 +129,7 @@ export default class GithubClient {
131129

132130
async updateBranchHead(sha: string) {
133131
const res = await requestUrl({
134-
url: `https://api.github.com/repos/${this.owner}/${this.repo}/git/refs/heads/${this.branch}`,
132+
url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/git/refs/heads/${this.settings.githubBranch}`,
135133
headers: this.headers(),
136134
method: "PATCH",
137135
body: JSON.stringify({
@@ -171,13 +169,13 @@ export default class GithubClient {
171169
*/
172170
async createFile(path: string, content: string, message: string) {
173171
const res = await requestUrl({
174-
url: `https://api.github.com/repos/${this.owner}/${this.repo}/contents/${path}`,
172+
url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/contents/${path}`,
175173
headers: this.headers(),
176174
method: "PUT",
177175
body: JSON.stringify({
178176
message: message,
179177
content: content,
180-
branch: this.branch,
178+
branch: this.settings.githubBranch,
181179
}),
182180
throw: false,
183181
});

src/sync-manager.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ export default class SyncManager {
4040
private logger: Logger,
4141
) {
4242
this.metadataStore = new MetadataStore(this.vault);
43-
this.client = new GithubClient(
44-
this.settings.githubToken,
45-
this.settings.githubOwner,
46-
this.settings.githubRepo,
47-
this.settings.githubBranch,
48-
this.logger,
49-
);
43+
this.client = new GithubClient(this.settings, this.logger);
5044
this.eventsListener = new EventsListener(
5145
this.vault,
5246
this.metadataStore,

0 commit comments

Comments
 (0)