Replies: 4 comments 19 replies
-
Can you try this, and tell me what output you get when you run it? let octokit: Octokit;
const authToken = this.ghTokens.get(module.source.gitRepoUrl);
if (authToken) {
octokit = new Octokit({
baseUrl: module.source.getGitHubUrl(),
auth: authToken,
log: console
});
} else {
logger.warn(`No authentication token found for repository ${module.source.gitRepoUrl}`);
octokit = new Octokit({
baseUrl: module.source.getGitHubUrl(),
log: console
});
}
(async () => {
const response = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: module.source.getRepoOwner(),
repo: module.source.getRepo(),
path: `${module.source.gitFolder ? `${module.source.gitFolder}/` : ''}${METADATA_FILE_NAME}`,
ref: module.source.getBranch()
});
console.log(response);
})(); It adds logging to the |
Beta Was this translation helpful? Give feedback.
-
@timrogers Thx for the tip! I'm trying your change but getting no output. I can see I tried grabbing the response outside the IIFE afterwards, but it's undefined. let response: unknown;
(async () => {
response = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: module.source.getRepoOwner(),
repo: module.source.getRepo(),
path: `${module.source.gitFolder ? `${module.source.gitFolder}/` : ''}${METADATA_FILE_NAME}`,
ref: module.source.getBranch()
});
// eslint-disable-next-line no-console
console.log(`CONSOLE LOG GET response: ${response}`);
})();
logger.trace(`GET repo response: ${JSON.stringify(response)}`); |
Beta Was this translation helpful? Give feedback.
-
// set up octokit
let octokit: Octokit;
const authToken = this.ghTokens.get(module.source.gitRepoUrl);
if (authToken) {
octokit = new Octokit({
baseUrl: module.source.getGitHubUrl(),
auth: authToken,
log: console
});
} else {
logger.warn(`No authentication token found for repository ${module.source.gitRepoUrl}`);
octokit = new Octokit({
baseUrl: module.source.getGitHubUrl(),
log: console
});
}
let response: unknown;
(async () => {
response = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: module.source.getRepoOwner(),
repo: module.source.getRepo(),
path: `${module.source.gitFolder ? `${module.source.gitFolder}/` : ''}${METADATA_FILE_NAME}`,
ref: module.source.getBranch()
});
// eslint-disable-next-line no-console
console.log(`CONSOLE LOG GET response: ${response}`);
})();
logger.trace(`GET repo response: ${JSON.stringify(response)}`); |
Beta Was this translation helpful? Give feedback.
-
@timrogers I reworked my stack to use async and await throughout. However when it gets to the // set up octokit
let octokit: Octokit;
const authToken = this.ghTokens.get(module.source.gitRepoUrl);
if (authToken) {
octokit = new Octokit({
baseUrl: module.source.getGitHubUrl(),
auth: authToken,
log: console
});
} else {
logger.warn(`No authentication token found for repository ${module.source.gitRepoUrl}`);
octokit = new Octokit({
baseUrl: module.source.getGitHubUrl(),
log: console
});
}
// this is to avoid making parseModule async.
logger.debug(
`Retrieving metadata file from repo ${module.source.getRepoUrl()} in path ${
module.source.gitFolder
} in branch ${module.source.getBranch()}`
);
try {
const response = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: module.source.getRepoOwner(),
repo: module.source.getRepo(),
path: `${module.source.gitFolder ? `${module.source.gitFolder}/` : ''}${METADATA_FILE_NAME}`,
ref: module.source.getBranch()
});
logger.trace(`GET repo response: ${JSON.stringify(response)}`);
} catch (error) {
logger.error(`Error getting metadata file from repository ${module.source.getRepoUrl()}: ${error}`);
} |
Beta Was this translation helpful? Give feedback.
-
I am trying to download a file from a repo in a non-async function. The
request
response is coming back as{}
. What are the possible causes for getting back an empty response object?Beta Was this translation helpful? Give feedback.
All reactions