Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update api response format #78

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function run() {
const githubToken = getInput("github-token");
const octokit = new Octokit({ auth: githubToken });

fetch("https://db.ygoprodeck.com/api/v7/randomcard.php")
fetch("https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust")
.then((response) => {
if(!response.ok){
console.error('response.ok:', response.ok);
Expand All @@ -19,11 +19,15 @@ async function run() {
return response.json();
})
.then((data) => {
const cardName = data.name;
if (!(('card_images' in data) && Array.isArray(data.card_images) && data.card_images.length > 0)) {
if (!(Array.isArray(data.card_images) && data.length > 0)) {
throw new Error("Failed to get card");
}
const card = data[0];
const cardName = card.name;
if (!(('card_images' in card) && Array.isArray(card.card_images) && card.card_images.length > 0)) {
throw new Error("Failed to get card images");
}
const imageUrl = data.card_images[0].image_url;
const imageUrl = card.card_images[0].image_url;

octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
Expand Down