1- import fetch from "node-fetch" ;
21import { getInput , setFailed } from "@actions/core" ;
32import { context } from "@actions/github" ;
43import { Octokit } from "@octokit/core" ;
4+ import fetch from "node-fetch" ;
55
66async function run ( ) {
77 try {
88 const githubToken = getInput ( "github-token" ) ;
99 const octokit = new Octokit ( { auth : githubToken } ) ;
1010
11- fetch ( "https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust" )
11+ fetch (
12+ "https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust" ,
13+ )
1214 . then ( ( response ) => {
13- if ( ! response . ok ) {
14- console . error ( ' response.ok:' , response . ok ) ;
15- console . error ( ' esponse.status:' , response . status ) ;
16- console . error ( ' esponse.statusText:' , response . statusText ) ;
15+ if ( ! response . ok ) {
16+ console . error ( " response.ok:" , response . ok ) ;
17+ console . error ( " esponse.status:" , response . status ) ;
18+ console . error ( " esponse.statusText:" , response . statusText ) ;
1719 throw new Error ( "Failed to fetch random card" ) ;
1820 }
1921 return response . json ( ) ;
2022 } )
2123 . then ( ( data ) => {
22- if ( ! ( ( 'data' in data ) && Array . isArray ( data [ "data" ] ) && data [ "data" ] . length > 0 ) ) {
24+ if (
25+ ! ( "data" in data && Array . isArray ( data . data ) && data . data . length > 0 )
26+ ) {
2327 throw new Error ( "Failed to get card" ) ;
2428 }
25- const card = data [ " data" ] [ 0 ] ;
29+ const card = data . data [ 0 ] ;
2630 const cardName = card . name ;
27- if ( ! ( ( 'card_images' in card ) && Array . isArray ( card . card_images ) && card . card_images . length > 0 ) ) {
31+ if (
32+ ! (
33+ "card_images" in card &&
34+ Array . isArray ( card . card_images ) &&
35+ card . card_images . length > 0
36+ )
37+ ) {
2838 throw new Error ( "Failed to get card images" ) ;
2939 }
3040 const imageUrl = card . card_images [ 0 ] . image_url ;
@@ -36,7 +46,7 @@ async function run() {
3646 owner : context . repo . owner ,
3747 repo : context . repo . repo ,
3848 body : `_**Draw "${ cardName } " !**_\n\n` ,
39- }
49+ } ,
4050 ) ;
4151 } ) ;
4252 } catch ( error ) {
0 commit comments