Skip to content

Commit

Permalink
feat: add dogs as an option to post
Browse files Browse the repository at this point in the history
  • Loading branch information
Chesire committed Apr 3, 2021
1 parent db7bc96 commit de659a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ jobs:
with:
okami-token: ${{ secrets.GITHUB_TOKEN }}
animal-type: "fox"

- name: Post dog
uses: ./
with:
okami-token: ${{ secrets.GITHUB_TOKEN }}
animal-type: "dog"
27 changes: 23 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var animal = {
shiba: "SHIBA",
cat: "CAT",
bird: "BIRD",
fox: "FOX"
fox: "FOX",
dog: "DOG"
}

async function run() {
Expand All @@ -24,8 +25,12 @@ async function run() {
}

const image = await getAnimalImageUrl()
console.log(`image url - ${image}`)
postImageToPR(context, image)
if (image === "") {
console.error("No image url found! Not posting a comment")
} else {
console.log(`image url - ${image}`)
postImageToPR(context, image)
}
}

async function getAnimalImageUrl() {
Expand All @@ -40,13 +45,15 @@ async function getAnimalImageUrl() {
return getBirdImage()
} else if (animalType == animal.fox) {
return getFoxImage()
} else if (animalType == animal.dog) {
return getDogImage()
} else {
core.setFailed("Invalid animal input" + animalInput)
}
}

async function getShibaImage() {
return getShibeOnlineImage("shibe")
return getShibeOnlineImage("shibes")
}

async function getCatImage() {
Expand Down Expand Up @@ -81,6 +88,18 @@ async function getFoxImage() {
return pictureUrl
}

async function getDogImage() {
var pictureUrl = ""
try {
const response = await axios.get("https://dog.ceo/api/breeds/image/random")
pictureUrl = response.message
} catch (error) {
console.error(error)
}

return pictureUrl
}

async function postImageToPR(context, picture) {
const token = core.getInput('okami-token')
const octokit = github.getOctokit(token)
Expand Down
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var animal = {
shiba: "SHIBA",
cat: "CAT",
bird: "BIRD",
fox: "FOX"
fox: "FOX",
dog: "DOG"
}

async function run() {
Expand Down Expand Up @@ -37,6 +38,8 @@ async function getAnimalImageUrl() {
return getBirdImage()
} else if (animalType == animal.fox) {
return getFoxImage()
} else if (animalType == animal.dog) {
return getDogImage()
} else {
core.setFailed("Invalid animal input" + animalInput)
}
Expand Down Expand Up @@ -78,6 +81,18 @@ async function getFoxImage() {
return pictureUrl
}

async function getDogImage() {
var pictureUrl = ""
try {
const response = await axios.get("https://dog.ceo/api/breeds/image/random")
pictureUrl = response.message
} catch (error) {
console.error(error)
}

return pictureUrl
}

async function postImageToPR(context, picture) {
const token = core.getInput('okami-token')
const octokit = github.getOctokit(token)
Expand Down

0 comments on commit de659a3

Please sign in to comment.