-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: 'Push web notification' | ||
description: 'Push the web notification if there are new posts.' | ||
inputs: | ||
who-to-greet: # id of input | ||
description: 'Who to greet' | ||
required: true | ||
default: 'World' | ||
outputs: | ||
time: # id of output | ||
description: 'The time we greeted you' | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const fetch = require('node-fetch'); | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
|
||
try { | ||
// Get newPost.json from your site. | ||
var newPostOnlineSite = await fetch('https://www.inevitable.tech/newPost.json') | ||
newPostOnlineSite = await newPostOnlineSite.json(); | ||
newPostOnlineSite = JSON.parse(JSON.stringify(newPostOnlineSite)); | ||
// Get newPost.json from your repo. | ||
var newPostRepo = await fetch('https://raw.githubusercontent.com/glazec/glazec.github.io/master/newPost.json') | ||
newPostRepo = await newPostRepo.json(); | ||
newPostRepo = JSON.parse(JSON.stringify(newPostRepo)) | ||
console.log(newPostOnlineSite) | ||
console.log(newPostRepo) | ||
|
||
//publish the site | ||
fetch(process.env.buildHook, { method: 'POST' }); | ||
|
||
if (newPostOnlineSite.id != newPostRepo.id) { | ||
// push new Post notificaiton | ||
|
||
payload = { "title": newPostRepo.title, "message": newPostRepo.summary, "target_url": newPostRepo.url } | ||
const response = await fetch('https://app.webpushr.com/api/v1/notification/send/all', { | ||
method: 'POST', | ||
headers: { | ||
'webpushrKey': process.env.webpushrKey, | ||
'webpushrAuthToken': process.env.webpushrAuthToken, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(payload), | ||
}); | ||
const data = await response.json(); | ||
|
||
if (!response.ok) { | ||
// NOT res.status >= 200 && res.status < 300 | ||
return JSON.stringify({ statusCode: data.status, body: data.detail }); | ||
} | ||
return ( | ||
"Successfully push notification"), | ||
|
||
|
||
|
||
} | ||
else { | ||
return ( | ||
"No New Post detected."); | ||
} | ||
|
||
} catch (error) { | ||
core.setFailed(error.message); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.