spec-up-t 1.0.91 → 1.0.92
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/assets/compiled/body.js +1 -1
- package/assets/compiled/head.css +1 -1
- package/assets/css/index.css +202 -150
- package/index.js +0 -3
- package/package.json +2 -1
- package/src/add-remove-xref-source.js +171 -0
- package/src/{get-xtrefs-data.js → collect-external-references.js} +13 -42
- package/src/collectExternalReferences/fetchTermsFromGitHubRepository.js +237 -0
- package/src/{get-xtrefs-data → collectExternalReferences}/matchTerm.js +4 -3
- package/src/collectExternalReferences/processXTrefsData.js +53 -0
- package/src/config/paths.js +1 -0
- package/src/configure.js +96 -0
- package/src/init.js +2 -8
- package/src/prepare-tref.js +21 -4
- package/src/utils/doesUrlExist.js +18 -10
- package/src/utils/isLineWithDefinition.js +13 -0
- package/src/get-xtrefs-data/matchTerm.1.js +0 -23
- package/src/get-xtrefs-data/searchGitHubCode.1.js +0 -69
- package/src/get-xtrefs-data/searchGitHubCode.2.js +0 -77
- package/src/get-xtrefs-data/searchGitHubCode.3.js +0 -85
- package/src/get-xtrefs-data/searchGitHubCode.4.js +0 -92
- package/src/get-xtrefs-data/searchGitHubCode.5.js +0 -97
- package/src/get-xtrefs-data/searchGitHubCode.6.js +0 -101
- package/src/get-xtrefs-data/searchGitHubCode.js +0 -97
- /package/src/{get-xtrefs-data → collectExternalReferences}/checkRateLimit.js +0 -0
- /package/src/{get-xtrefs-data → collectExternalReferences}/setupFetchHeaders.js +0 -0
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
async function searchGitHubCode(GITHUB_API_TOKEN, searchString, owner, repo, subdirectory) {
|
|
2
|
-
const { Octokit } = await import("octokit");
|
|
3
|
-
const { throttling } = await import("@octokit/plugin-throttling");
|
|
4
|
-
|
|
5
|
-
// Create a throttled Octokit instance
|
|
6
|
-
const ThrottledOctokit = Octokit.plugin(throttling);
|
|
7
|
-
const octokit = new ThrottledOctokit({
|
|
8
|
-
auth: GITHUB_API_TOKEN,
|
|
9
|
-
throttle: {
|
|
10
|
-
onRateLimit: (retryAfter, options) => {
|
|
11
|
-
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
12
|
-
if (options.request.retryCount <= 1) {
|
|
13
|
-
console.log(`Retrying after ${retryAfter} seconds...`);
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
onAbuseLimit: (retryAfter, options) => {
|
|
18
|
-
console.warn(`Abuse detected for request ${options.method} ${options.url}`);
|
|
19
|
-
},
|
|
20
|
-
onSecondaryRateLimit: (retryAfter, options) => {
|
|
21
|
-
console.warn(`Secondary rate limit hit for request ${options.method} ${options.url}`);
|
|
22
|
-
if (options.request.retryCount <= 1) {
|
|
23
|
-
console.log(`Retrying after ${retryAfter} seconds...`);
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
// Perform the search using Octokit with exact match
|
|
32
|
-
const searchResponse = await octokit.rest.search.code({
|
|
33
|
-
q: `"${searchString}" repo:${owner}/${repo} path:${subdirectory}`, // Exact match in subdirectory
|
|
34
|
-
headers: {
|
|
35
|
-
Accept: "application/vnd.github.v3.text-match+json", // Include text-match media type
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Log the search results
|
|
40
|
-
console.log("Total results:", searchResponse.data.total_count);
|
|
41
|
-
|
|
42
|
-
// Fetch the content of each file
|
|
43
|
-
for (const item of searchResponse.data.items) {
|
|
44
|
-
// Check if text_matches exists and is not empty
|
|
45
|
-
if (!item.text_matches || item.text_matches.length === 0) {
|
|
46
|
-
console.log(`Skipping ${item.path}: No text matches found.`);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Check if the match is in the first line using text_matches
|
|
51
|
-
const isFirstLineMatch = item.text_matches.some(match => {
|
|
52
|
-
if (!match.fragment) {
|
|
53
|
-
console.log(`Skipping ${item.path}: No fragment found in text match.`);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const firstLine = match.fragment.split("\n")[0];
|
|
58
|
-
return firstLine.includes(searchString);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (!isFirstLineMatch) {
|
|
62
|
-
console.log(`Skipping ${item.path}: Match not in the first line.`);
|
|
63
|
-
continue; // Skip this file
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Fetch file content
|
|
67
|
-
let content = "";
|
|
68
|
-
try {
|
|
69
|
-
const fileContentResponse = await octokit.rest.repos.getContent({
|
|
70
|
-
owner: item.repository.owner.login, // Repository owner
|
|
71
|
-
repo: item.repository.name, // Repository name
|
|
72
|
-
path: item.path, // File path
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Decode the file content (it's base64-encoded)
|
|
76
|
-
if (fileContentResponse.data.content) {
|
|
77
|
-
content = Buffer.from(fileContentResponse.data.content, "base64").toString("utf-8");
|
|
78
|
-
} else {
|
|
79
|
-
// If the file is larger than 1 MB, GitHub's API will return a download URL instead of the content.
|
|
80
|
-
console.log("File is too large. Download URL:", fileContentResponse.data.download_url);
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error(`Error fetching content for ${item.path}:`, error);
|
|
84
|
-
content = ""; // Set content to an empty string if there's an error
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Attach the content to the item
|
|
88
|
-
item.content = content;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return searchResponse;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error("Error searching GitHub or fetching file content:", error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.searchGitHubCode = searchGitHubCode;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
async function searchGitHubCode(GITHUB_API_TOKEN, searchString, owner, repo, subdirectory) {
|
|
2
|
-
const { Octokit } = await import("octokit");
|
|
3
|
-
const { throttling } = await import("@octokit/plugin-throttling");
|
|
4
|
-
|
|
5
|
-
// Create a throttled Octokit instance
|
|
6
|
-
const ThrottledOctokit = Octokit.plugin(throttling);
|
|
7
|
-
const octokit = new ThrottledOctokit({
|
|
8
|
-
auth: GITHUB_API_TOKEN,
|
|
9
|
-
throttle: {
|
|
10
|
-
onRateLimit: (retryAfter, options) => {
|
|
11
|
-
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
12
|
-
if (!process.env.GITHUB_API_TOKEN) {
|
|
13
|
-
console.warn('GitHub API rate limit exceeded. See <a target="_blank" rel="noopener" href="https://trustoverip.github.io/spec-up-t-website/docs/github-token/">documentation</a> for more info.');
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
if (options.request.retryCount <= 1) {
|
|
17
|
-
console.log(`Retrying after ${retryAfter} seconds...`);
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
onAbuseLimit: (retryAfter, options) => {
|
|
22
|
-
console.warn(`Abuse detected for request ${options.method} ${options.url}`);
|
|
23
|
-
},
|
|
24
|
-
onSecondaryRateLimit: (retryAfter, options) => {
|
|
25
|
-
console.warn(`Secondary rate limit hit for request ${options.method} ${options.url}`);
|
|
26
|
-
if (options.request.retryCount <= 1) {
|
|
27
|
-
console.log(`Retrying after ${retryAfter} seconds...`);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
// Perform the search using Octokit with exact match
|
|
36
|
-
const searchResponse = await octokit.rest.search.code({
|
|
37
|
-
q: `"${searchString}" repo:${owner}/${repo} path:${subdirectory}`, // Exact match in subdirectory
|
|
38
|
-
headers: {
|
|
39
|
-
Accept: "application/vnd.github.v3.text-match+json", // Include text-match media type
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Log the search results
|
|
44
|
-
console.log("Total results:", searchResponse.data.total_count);
|
|
45
|
-
|
|
46
|
-
// Fetch the content of each file
|
|
47
|
-
for (const item of searchResponse.data.items) {
|
|
48
|
-
// Check if text_matches exists and is not empty
|
|
49
|
-
if (!item.text_matches || item.text_matches.length === 0) {
|
|
50
|
-
console.log(`Skipping ${item.path}: No text matches found.`);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Check if the match is in the first line using text_matches
|
|
55
|
-
const isFirstLineMatch = item.text_matches.some(match => {
|
|
56
|
-
if (!match.fragment) {
|
|
57
|
-
console.log(`Skipping ${item.path}: No fragment found in text match.`);
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const firstLine = match.fragment.split("\n")[0];
|
|
62
|
-
return firstLine.includes(searchString);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
if (!isFirstLineMatch) {
|
|
66
|
-
console.log(`Skipping ${item.path}: Match not in the first line.`);
|
|
67
|
-
continue; // Skip this file
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Fetch file content
|
|
71
|
-
let content = "";
|
|
72
|
-
try {
|
|
73
|
-
const fileContentResponse = await octokit.rest.repos.getContent({
|
|
74
|
-
owner: item.repository.owner.login, // Repository owner
|
|
75
|
-
repo: item.repository.name, // Repository name
|
|
76
|
-
path: item.path, // File path
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Decode the file content (it's base64-encoded)
|
|
80
|
-
if (fileContentResponse.data.content) {
|
|
81
|
-
content = Buffer.from(fileContentResponse.data.content, "base64").toString("utf-8");
|
|
82
|
-
} else {
|
|
83
|
-
// If the file is larger than 1 MB, GitHub's API will return a download URL instead of the content.
|
|
84
|
-
console.log("File is too large. Download URL:", fileContentResponse.data.download_url);
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error(`Error fetching content for ${item.path}:`, error);
|
|
88
|
-
content = ""; // Set content to an empty string if there's an error
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Attach the content to the item
|
|
92
|
-
item.content = content;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return searchResponse;
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error("Error searching GitHub or fetching file content:", error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
exports.searchGitHubCode = searchGitHubCode;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
async function searchGitHubCode(GITHUB_API_TOKEN, searchString, owner, repo, subdirectory) {
|
|
2
|
-
const { Octokit } = await import("octokit");
|
|
3
|
-
const { throttling } = await import("@octokit/plugin-throttling");
|
|
4
|
-
|
|
5
|
-
// Create a throttled Octokit instance
|
|
6
|
-
const ThrottledOctokit = Octokit.plugin(throttling);
|
|
7
|
-
const octokit = new ThrottledOctokit({
|
|
8
|
-
auth: GITHUB_API_TOKEN,
|
|
9
|
-
throttle: {
|
|
10
|
-
onRateLimit: (retryAfter, options) => {
|
|
11
|
-
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
12
|
-
if (options.request.retryCount <= 1) {
|
|
13
|
-
console.log(`Retrying after ${retryAfter} seconds...`);
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
onAbuseLimit: (retryAfter, options) => {
|
|
18
|
-
console.warn(`Abuse detected for request ${options.method} ${options.url}`);
|
|
19
|
-
},
|
|
20
|
-
onSecondaryRateLimit: (retryAfter, options) => {
|
|
21
|
-
console.warn(`Secondary rate limit hit for request ${options.method} ${options.url}`);
|
|
22
|
-
if (options.request.retryCount <= 1) {
|
|
23
|
-
console.log(`Retrying after ${retryAfter} seconds...`);
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
// Perform the search using Octokit with exact match
|
|
32
|
-
const searchResponse = await octokit.rest.search.code({
|
|
33
|
-
q: `"${searchString}" repo:${owner}/${repo} path:${subdirectory}`, // Exact match in subdirectory
|
|
34
|
-
headers: {
|
|
35
|
-
Accept: "application/vnd.github.v3.text-match+json", // Include text-match media type
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Log the search results
|
|
40
|
-
console.log("Total results:", searchResponse.data.total_count);
|
|
41
|
-
|
|
42
|
-
// Fetch the content of each file
|
|
43
|
-
for (const item of searchResponse.data.items) {
|
|
44
|
-
// Check if text_matches exists and is not empty
|
|
45
|
-
if (!item.text_matches || item.text_matches.length === 0) {
|
|
46
|
-
console.log(`Skipping ${item.path}: No text matches found.`);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Check if the match is in the first line using text_matches
|
|
51
|
-
const isFirstLineMatch = item.text_matches.some(match => {
|
|
52
|
-
if (!match.fragment) {
|
|
53
|
-
console.log(`Skipping ${item.path}: No fragment found in text match.`);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const firstLine = match.fragment.split("\n")[0];
|
|
58
|
-
return firstLine.includes(searchString);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (!isFirstLineMatch) {
|
|
62
|
-
console.log(`Skipping ${item.path}: Match not in the first line.`);
|
|
63
|
-
continue; // Skip this file
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Fetch file content
|
|
67
|
-
let content = "";
|
|
68
|
-
try {
|
|
69
|
-
const fileContentResponse = await octokit.rest.repos.getContent({
|
|
70
|
-
owner: item.repository.owner.login, // Repository owner
|
|
71
|
-
repo: item.repository.name, // Repository name
|
|
72
|
-
path: item.path, // File path
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Decode the file content (it's base64-encoded)
|
|
76
|
-
if (fileContentResponse.data.content) {
|
|
77
|
-
content = Buffer.from(fileContentResponse.data.content, "base64").toString("utf-8");
|
|
78
|
-
} else {
|
|
79
|
-
// If the file is larger than 1 MB, GitHub's API will return a download URL instead of the content.
|
|
80
|
-
console.log("File is too large. Download URL:", fileContentResponse.data.download_url);
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error(`Error fetching content for ${item.path}:`, error);
|
|
84
|
-
content = ""; // Set content to an empty string if there's an error
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Attach the content to the item
|
|
88
|
-
item.content = content;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return searchResponse;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error("Error searching GitHub or fetching file content:", error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.searchGitHubCode = searchGitHubCode;
|
|
File without changes
|
|
File without changes
|