Skip to content

Commit

Permalink
Fixing if GITHUB_PAT is not set.
Browse files Browse the repository at this point in the history
  • Loading branch information
amherag committed Sep 14, 2022
1 parent d47ead6 commit 61e9bd8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 43 deletions.
14 changes: 8 additions & 6 deletions scripts/releases_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ const repositories = [
];

const getReleases = async (repository) => {
const reqOpts = {
headers: {
Accept: 'application/vnd.github+json',
Authorization: ''
}
};
if (process.env.GITHUB_PAT) reqOpts.headers['Authorization'] = `Bearer ${process.env.GITHUB_PAT}`;
const result = await axios.get(
`https://api.github.com/repos/pointnetwork/${repository}/releases`,
{
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${process.env.GITHUB_PAT}`
}
});
reqOpts);
return result.data.sort((a, b) =>
(Date.parse(a.created_at) > Date.parse(b.created_at)) ? 1 : -1);
};
Expand Down
23 changes: 13 additions & 10 deletions shared/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ const getLatestReleaseFromGithub: (
) => Promise<string> = async repository => {
try {
if (isTestEnv()) return getReleaseFromGithub(repository);
const reqOpts = {
headers: {
'user-agent': 'node.js',
'Accept': 'application/vnd.github+json',
'Authorization': ''
}
};
if (process.env.GITHUB_PAT) reqOpts.headers['Authorization'] = `Bearer ${process.env.GITHUB_PAT}`;
const res = await axios.get(
`${getGithubAPIURL()}/repos/pointnetwork/${repository}/releases/latest`,
{
headers: {
'user-agent': 'node.js',
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${process.env.GITHUB_PAT}`
}
}
reqOpts
);
return res.data.tag_name;
} catch (error) {
Expand Down Expand Up @@ -288,14 +290,15 @@ const isNewDashboardReleaseAvailable = async () => {
try {
const githubAPIURL = getGithubAPIURL();
const url = `${githubAPIURL}/repos/pointnetwork/pointnetwork-dashboard/releases/latest`;
const headers = {
const reqOpts = {
headers: {
'user-agent': 'node.js',
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${process.env.GITHUB_PAT}`
'Authorization': ''
}
};
const res = await axios.get(url, headers);
if (process.env.GITHUB_PAT) reqOpts.headers['Authorization'] = `Bearer ${process.env.GITHUB_PAT}`;
const res = await axios.get(url, reqOpts);
const latestVersion = res.data.tag_name;

if (latestVersion.slice(1) > getInstalledDashboardVersion()) {
Expand Down
13 changes: 8 additions & 5 deletions src/firefox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ class Firefox {
const githubUrl = `${githubAPIURL}/repos/${owner}/${repo}/releases/latest`;
const fallback = `${githubURL}/${owner}/${repo}/releases/download/91.7.1-58/point-browser-portable-win64-91.7.1-57.zip`;
const re = /point-browser-portable-win64-\d+.\d+.\d+(-\d+)?.zip/;
const headers = {
'user-agent': 'node.js',
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${process.env.GITHUB_PAT}`
const reqOpts = {
headers: {
'user-agent': 'node.js',
'Accept': 'application/vnd.github+json',
'Authorization': ''
}
};
if (process.env.GITHUB_PAT) reqOpts.headers['Authorization'] = `Bearer ${process.env.GITHUB_PAT}`;

try {
const {data} = await axios.get<GithubRelease>(githubUrl, {headers});
const {data} = await axios.get<GithubRelease>(githubUrl, reqOpts);
const browserAsset = data.assets.find(a => re.test(a.name));

if (!browserAsset) {
Expand Down
22 changes: 0 additions & 22 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,7 @@ class Node {
* Returns the download URL for the version provided and the file name provided
*/
async getDownloadURL(filename: string, version: string): string {
// const ghAPIURL = helpers.getGithubAPIURL();
// const ghURL = helpers.getGithubURL();
// const reqOpts = {
// headers: {
// Accept: 'application/vnd.github+json',
// Authorization: ''
// }
// };
// if (process.env.GITHUB_PAT) reqOpts.headers['Authorization'] = `Bearer ${process.env.GITHUB_PAT}`;

// const releases = await axios.get(`${ghAPIURL}/repos/pointnetwork/pointnetwork/releases`, reqOpts);
// const release = releases.data.find((obj: any) => obj.tag_name == version);
// console.log({release})
// const assetsRes = await axios.get(`${ghAPIURL}/repos/pointnetwork/pointnetwork/releases/${release.id}/assets`, reqOpts);
// console.log(`${ghAPIURL}/repos/pointnetwork/pointnetwork/releases/${release.id}/assets`);
// console.log(assetsRes.data);
// const assetInfo = assetsRes.data.find((asset: any) => asset.name === filename);
// const assetURL = assetInfo.browser_download_url;

// console.log(assetInfo.browser_download_url);
return `${helpers.getGithubURL()}/pointnetwork/pointnetwork/releases/download/${version}/${filename}`;
// return `${ghAPIURL}/repos/pointnetwork/pointnetwork/releases/assets/${assetInfo.id}`;
// return assetURL.replace('https://github.com', ghURL);
}

/**
Expand Down

0 comments on commit 61e9bd8

Please sign in to comment.