Skip to content

Commit

Permalink
fix:Simplify-error-handling(#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshaydewan committed Oct 21, 2024
1 parent 3a8f69a commit 41aaa49
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions scripts/dashboard/build-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@ async function getHotDiscussions(discussions) {
};
} catch (e) {
console.error(
`there was some issues while parsing this item: ${JSON.stringify(
`There was some issues while parsing this item: ${JSON.stringify(
discussion
)}`
);
throw e;
throw e; // Throw the error instead of logging

Check warning on line 52 in scripts/dashboard/build-dashboard.js

View check run for this annotation

Codecov / codecov/patch

scripts/dashboard/build-dashboard.js#L52

Added line #L52 was not covered by tests
}
})
);
result.sort((ElemA, ElemB) => ElemB.score - ElemA.score);
const filteredResult = result.filter(issue => issue.author !== 'asyncapi-bot');
return filteredResult.slice(0, 12);
}

async function writeToFile(content) {
writeFileSync(
resolve(__dirname, '..', '..', 'dashboard.json'),
JSON.stringify(content, null, ' ')
);
}

async function mapGoodFirstIssues(issues) {
return issues.map((issue) => ({
id: issue.id,
Expand All @@ -87,7 +89,6 @@ function getLabel(issue, filter) {
return result && result.name.split('/')[1];
}


function monthsSince(date) {
const seconds = Math.floor((new Date() - new Date(date)) / 1000);
// 2592000 = number of seconds in a month = 30 * 24 * 60 * 60
Expand All @@ -112,7 +113,7 @@ async function getDiscussions(query, pageSize, endCursor = null) {
`limit = ${result.rateLimit.limit}`,
`remaining = ${result.rateLimit.remaining}`,
`resetAt = ${result.rateLimit.resetAt}`
)
);
}

const hasNextPage = result.search.pageInfo.hasNextPage;
Expand All @@ -126,23 +127,25 @@ async function getDiscussions(query, pageSize, endCursor = null) {
}
} catch (e) {
console.error(e);
throw e; // Throw the error instead of logging

Check warning on line 130 in scripts/dashboard/build-dashboard.js

View check run for this annotation

Codecov / codecov/patch

scripts/dashboard/build-dashboard.js#L130

Added line #L130 was not covered by tests
}
}

async function getDiscussionByID(isPR, id) {
try {
let result = await graphql(isPR ? Queries.pullRequestById : Queries.issueById, {
id,
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
},

}
);
});
return result;
} catch (e) {
console.error(e);
throw e; // Throw the error instead of logging

Check warning on line 145 in scripts/dashboard/build-dashboard.js

View check run for this annotation

Codecov / codecov/patch

scripts/dashboard/build-dashboard.js#L145

Added line #L145 was not covered by tests
}
}

async function start() {
try {
const [issues, PRs, rawGoodFirstIssues] = await Promise.all([
Expand All @@ -157,10 +160,12 @@ async function start() {
]);
writeToFile({ hotDiscussions, goodFirstIssues });
} catch (e) {
console.log('There were some issues parsing data from github.')
console.log('There were some issues parsing data from github.');

Check warning on line 163 in scripts/dashboard/build-dashboard.js

View check run for this annotation

Codecov / codecov/patch

scripts/dashboard/build-dashboard.js#L163

Added line #L163 was not covered by tests
console.log(e);
throw e; // Throw the error instead of logging

Check warning on line 165 in scripts/dashboard/build-dashboard.js

View check run for this annotation

Codecov / codecov/patch

scripts/dashboard/build-dashboard.js#L165

Added line #L165 was not covered by tests
}
}

start();

module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID }
module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID };

Check warning on line 171 in scripts/dashboard/build-dashboard.js

View check run for this annotation

Codecov / codecov/patch

scripts/dashboard/build-dashboard.js#L171

Added line #L171 was not covered by tests

0 comments on commit 41aaa49

Please sign in to comment.