@aspruyt/xfg 3.7.0 → 3.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,7 +24,13 @@ export interface RepoSettingsProcessorResult {
|
|
|
24
24
|
}
|
|
25
25
|
export declare class RepoSettingsProcessor implements IRepoSettingsProcessor {
|
|
26
26
|
private readonly strategy;
|
|
27
|
+
private readonly tokenManager;
|
|
27
28
|
constructor(strategy?: IRepoSettingsStrategy);
|
|
28
29
|
process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: RepoSettingsProcessorOptions): Promise<RepoSettingsProcessorResult>;
|
|
29
30
|
private applyChanges;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a GitHub App installation token for the given repo.
|
|
33
|
+
* Returns undefined if no token manager or token resolution fails.
|
|
34
|
+
*/
|
|
35
|
+
private getInstallationToken;
|
|
30
36
|
}
|
|
@@ -2,10 +2,19 @@ import { isGitHubRepo, getRepoDisplayName } from "./repo-detector.js";
|
|
|
2
2
|
import { GitHubRepoSettingsStrategy } from "./strategies/github-repo-settings-strategy.js";
|
|
3
3
|
import { diffRepoSettings, hasChanges } from "./repo-settings-diff.js";
|
|
4
4
|
import { formatRepoSettingsPlan, } from "./repo-settings-plan-formatter.js";
|
|
5
|
+
import { hasGitHubAppCredentials } from "./strategies/index.js";
|
|
6
|
+
import { GitHubAppTokenManager } from "./github-app-token-manager.js";
|
|
5
7
|
export class RepoSettingsProcessor {
|
|
6
8
|
strategy;
|
|
9
|
+
tokenManager;
|
|
7
10
|
constructor(strategy) {
|
|
8
11
|
this.strategy = strategy ?? new GitHubRepoSettingsStrategy();
|
|
12
|
+
if (hasGitHubAppCredentials()) {
|
|
13
|
+
this.tokenManager = new GitHubAppTokenManager(process.env.XFG_GITHUB_APP_ID, process.env.XFG_GITHUB_APP_PRIVATE_KEY);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.tokenManager = null;
|
|
17
|
+
}
|
|
9
18
|
}
|
|
10
19
|
async process(repoConfig, repoInfo, options) {
|
|
11
20
|
const repoName = getRepoDisplayName(repoInfo);
|
|
@@ -31,7 +40,9 @@ export class RepoSettingsProcessor {
|
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
try {
|
|
34
|
-
|
|
43
|
+
// Resolve App token if available, fall back to provided token
|
|
44
|
+
const effectiveToken = token ?? (await this.getInstallationToken(githubRepo));
|
|
45
|
+
const strategyOptions = { token: effectiveToken, host: githubRepo.host };
|
|
35
46
|
// Fetch current settings
|
|
36
47
|
const currentSettings = await this.strategy.getSettings(githubRepo, strategyOptions);
|
|
37
48
|
// Compute diff
|
|
@@ -94,4 +105,20 @@ export class RepoSettingsProcessor {
|
|
|
94
105
|
await this.strategy.setAutomatedSecurityFixes(repoInfo, automatedSecurityFixes, options);
|
|
95
106
|
}
|
|
96
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Resolves a GitHub App installation token for the given repo.
|
|
110
|
+
* Returns undefined if no token manager or token resolution fails.
|
|
111
|
+
*/
|
|
112
|
+
async getInstallationToken(repoInfo) {
|
|
113
|
+
if (!this.tokenManager) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const token = await this.tokenManager.getTokenForRepo(repoInfo);
|
|
118
|
+
return token ?? undefined;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
97
124
|
}
|