Skip to content

Commit

Permalink
feat: begin api request
Browse files Browse the repository at this point in the history
  • Loading branch information
Chesire committed Apr 2, 2021
1 parent 77f29ae commit 1ac7829
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
35 changes: 33 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports =

const core = __nccwpck_require__(698);
const github = __nccwpck_require__(695);
const https = __nccwpck_require__(211);

async function run() {
const context = github.context;
Expand All @@ -15,18 +16,48 @@ async function run() {
return;
}

// github.token ?
const token = core.getInput('okami-token');
const octokit = github.getOctokit(token);
const prNumber = context.payload.pull_request.number;

const picture = getShibaPicture()

octokit.issues.createComment({
...context.repo,
issue_number: prNumber,
body: "Test"
});
});
}

async function getShibaPicture() {
var result = '';
const options = {
hostname: 'shibe.online',
path: '/api/shibes',
method: 'GET'
}
// http://shibe.online/api/shibes?urls=[true/false]

const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)

res.on('data', d => {
result += d
})
res.on('error', error => {
console.log(`error occurred: ${error}`)
})
res.on('end', () => {
console.log(`ended ${result}`)
})
})

req.end()
return result
}


// /api/cats or birds at /api/birds
run();

/*
Expand Down
35 changes: 33 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const https = require('https');

async function run() {
const context = github.context;
Expand All @@ -8,18 +9,48 @@ async function run() {
return;
}

// github.token ?
const token = core.getInput('okami-token');
const octokit = github.getOctokit(token);
const prNumber = context.payload.pull_request.number;

const picture = getShibaPicture()

octokit.issues.createComment({
...context.repo,
issue_number: prNumber,
body: "Test"
});
});
}

async function getShibaPicture() {
var result = '';
const options = {
hostname: 'shibe.online',
path: '/api/shibes',
method: 'GET'
}
// http://shibe.online/api/shibes?urls=[true/false]

const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)

res.on('data', d => {
result += d
})
res.on('error', error => {
console.log(`error occurred: ${error}`)
})
res.on('end', () => {
console.log(`ended ${result}`)
})
})

req.end()
return result
}


// /api/cats or birds at /api/birds
run();

/*
Expand Down

0 comments on commit 1ac7829

Please sign in to comment.