ultimate-jekyll-manager 0.0.203 → 0.0.204
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.
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const jetpack = require('fs-jetpack');
|
|
4
4
|
|
|
5
|
+
// Load .env file from current working directory (project root)
|
|
6
|
+
require('dotenv').config({ path: path.join(process.cwd(), '.env') });
|
|
7
|
+
|
|
5
8
|
// Command Aliases
|
|
6
9
|
const DEFAULT = 'setup';
|
|
7
10
|
const ALIASES = {
|
|
@@ -6,6 +6,7 @@ const { execute } = require('node-powertools');
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Detects and sets GITHUB_REPOSITORY environment variable if not already set
|
|
9
|
+
* Uses GitHub API to verify/correct the owner in case repo was transferred
|
|
9
10
|
* @param {Object} logger - Logger instance for output
|
|
10
11
|
* @returns {Promise<string|null>} - Repository in format "owner/repo" or null if detection fails
|
|
11
12
|
*/
|
|
@@ -20,16 +21,54 @@ async function detectGitHubRepository(logger = console) {
|
|
|
20
21
|
|
|
21
22
|
// Parse GitHub repository from remote URL
|
|
22
23
|
// Supports: https://github.com/owner/repo.git, git@github.com:owner/repo.git
|
|
23
|
-
const match = result.match(/github\.com[:/]([^/]
|
|
24
|
+
const match = result.match(/github\.com[:/]([^/]+)\/([^.\s]+)/);
|
|
24
25
|
|
|
25
|
-
if (match) {
|
|
26
|
-
process.env.GITHUB_REPOSITORY = match[1];
|
|
27
|
-
logger.log(`Auto-detected repository from git remote: ${process.env.GITHUB_REPOSITORY}`);
|
|
28
|
-
return process.env.GITHUB_REPOSITORY;
|
|
29
|
-
} else {
|
|
26
|
+
if (!match) {
|
|
30
27
|
logger.warn(`⚠️ Could not parse GitHub repository from git remote URL: ${result}`);
|
|
31
28
|
return null;
|
|
32
29
|
}
|
|
30
|
+
|
|
31
|
+
let owner = match[1];
|
|
32
|
+
let repo = match[2];
|
|
33
|
+
|
|
34
|
+
// If GH_TOKEN is available, verify the current owner via GitHub API
|
|
35
|
+
// This handles cases where repos were transferred to a different owner
|
|
36
|
+
if (process.env.GH_TOKEN) {
|
|
37
|
+
try {
|
|
38
|
+
const { Octokit } = require('@octokit/rest');
|
|
39
|
+
const octokit = new Octokit({ auth: process.env.GH_TOKEN });
|
|
40
|
+
|
|
41
|
+
// GitHub API automatically redirects to the current location of transferred repos
|
|
42
|
+
const { data } = await octokit.repos.get({ owner, repo });
|
|
43
|
+
|
|
44
|
+
// Check if the repo was transferred (owner changed)
|
|
45
|
+
if (data.owner.login !== owner) {
|
|
46
|
+
logger.log(`🔄 Repository was transferred: ${owner}/${repo} → ${data.owner.login}/${repo}`);
|
|
47
|
+
|
|
48
|
+
// Update the local git remote to the new owner
|
|
49
|
+
const newOwner = data.owner.login;
|
|
50
|
+
const newUrl = result.includes('git@')
|
|
51
|
+
? `git@github.com:${newOwner}/${repo}.git`
|
|
52
|
+
: `https://github.com/${newOwner}/${repo}.git`;
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
await execute(`git remote set-url origin ${newUrl}`, { log: false });
|
|
56
|
+
logger.log(`✅ Updated git remote origin to: ${newUrl}`);
|
|
57
|
+
} catch (remoteError) {
|
|
58
|
+
logger.warn(`⚠️ Could not update git remote: ${remoteError.message}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
owner = newOwner;
|
|
62
|
+
}
|
|
63
|
+
} catch (apiError) {
|
|
64
|
+
// If API call fails, fall back to git remote value
|
|
65
|
+
logger.warn(`⚠️ Could not verify repository owner via GitHub API: ${apiError.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
process.env.GITHUB_REPOSITORY = `${owner}/${repo}`;
|
|
70
|
+
logger.log(`Auto-detected repository from git remote: ${process.env.GITHUB_REPOSITORY}`);
|
|
71
|
+
return process.env.GITHUB_REPOSITORY;
|
|
33
72
|
} catch (e) {
|
|
34
73
|
// Ignore errors from git command (e.g., not a git repo, no remote)
|
|
35
74
|
if (logger.warn) {
|
|
@@ -101,6 +101,9 @@ class GitHubCache {
|
|
|
101
101
|
this.logger.log(`📦 Zip file: ${zipFileName}`);
|
|
102
102
|
this.logger.log(`📂 Extract directory: ${extractDir}`);
|
|
103
103
|
this.logger.log(`📁 Directory contents: ${JSON.stringify(dirContents)}`);
|
|
104
|
+
this.logger.log(`🔍 Debug - this.owner: ${this.owner}, this.repo: ${this.repo}`);
|
|
105
|
+
this.logger.log(`🔍 Debug - GITHUB_REPOSITORY env: ${process.env.GITHUB_REPOSITORY}`);
|
|
106
|
+
this.logger.log(`🔍 Debug - Pattern being used: ^${this.owner}-${this.repo}-[a-f0-9]+$`);
|
|
104
107
|
|
|
105
108
|
// GitHub zipball format: {owner}-{repo}-{sha}
|
|
106
109
|
// Match this pattern to avoid picking up other cache directories (like imagemin, translation)
|