Added Gitea webhooks for Crawler project
This commit is contained in:
parent
3bef13b9fc
commit
6b4fcf387f
147
server.js
147
server.js
@ -197,6 +197,153 @@ app.post('/addItem',async(req,res)=>{
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post("/postUpdate",(req,res)=>{
|
||||||
|
res.status(200).send("Thank you!")
|
||||||
|
if(req.body.action){
|
||||||
|
switch(req.body.action){
|
||||||
|
case "opened":{
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Issue #"+req.body.number+" opened by "+req.body.issue.user.username,
|
||||||
|
icon_url:req.body.issue.user.avatar_url
|
||||||
|
},
|
||||||
|
color:11731199,
|
||||||
|
description:"**"+req.body.issue.title+":**\n\n"+req.body.issue.body+"\n\n[Link to Issue]("+req.body.issue.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "reopened":{
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Issue #"+req.body.number+" re-opened by "+req.body.issue.user.username,
|
||||||
|
icon_url:req.body.issue.user.avatar_url
|
||||||
|
},
|
||||||
|
color:13789695,
|
||||||
|
description:"**"+req.body.issue.title+":**\n\n"+req.body.issue.body+"\n\n[Link to Issue]("+req.body.issue.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "assigned":{
|
||||||
|
var assignedList=""
|
||||||
|
for(assignee of req.body.issue.assignees){
|
||||||
|
if(assignedList.length==0){
|
||||||
|
assignedList+=assignee.username
|
||||||
|
}else{
|
||||||
|
assignedList+=","+assignee.username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Assigned users to Issue #"+req.body.number,
|
||||||
|
icon_url:req.body.issue.user.avatar_url
|
||||||
|
},
|
||||||
|
color:50363,
|
||||||
|
description:"Assigned **"+assignedList+"** to Issue **"+req.body.issue.title+"**\n\n[Link to Issue]("+req.body.issue.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "label_updated":{
|
||||||
|
var labelsList=""
|
||||||
|
for(label of req.body.issue.labels){
|
||||||
|
if(labelsList.length==0){
|
||||||
|
labelsList+="- **"+label.name+"**"
|
||||||
|
}else{
|
||||||
|
labelsList+="\n- **"+label.name+"**"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Assigned labels to Issue #"+req.body.number,
|
||||||
|
icon_url:req.body.issue.user.avatar_url
|
||||||
|
},
|
||||||
|
color:365568,
|
||||||
|
description:"Labels set for Issue **"+req.body.issue.title+"**:\n"+labelsList+"\n\n[Link to Issue]("+req.body.issue.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "created":{
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Comment posted on Issue #"+req.body.issue.number,
|
||||||
|
icon_url:req.body.comment.user.avatar_url
|
||||||
|
},
|
||||||
|
color:11731199,
|
||||||
|
description:"__**"+req.body.issue.title+"**__\nCommented by **"+req.body.comment.user.username+":**\n"+req.body.comment.body+"\n\n[Link to Comment]("+req.body.comment.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "edited":{
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Comment edited on Issue #"+req.body.issue.number,
|
||||||
|
icon_url:req.body.comment.user.avatar_url
|
||||||
|
},
|
||||||
|
color:11731199,
|
||||||
|
description:"__**"+req.body.issue.title+"**__\nCommented by **"+req.body.comment.user.username+":**\n"+req.body.comment.body+"\n\n[Link to Comment]("+req.body.comment.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "deleted":{
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Comment deleted on Issue #"+req.body.issue.number,
|
||||||
|
icon_url:req.body.comment.user.avatar_url
|
||||||
|
},
|
||||||
|
color:11731199,
|
||||||
|
description:"__**"+req.body.issue.title+"**__\nCommented by **"+req.body.comment.user.username+":**\n~~"+req.body.comment.body+"~~\n\n[Link to Comment]("+req.body.comment.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
case "closed":{
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:"Issue #"+req.body.number+" closed by "+req.body.issue.user.username,
|
||||||
|
icon_url:req.body.issue.user.avatar_url
|
||||||
|
},
|
||||||
|
color:9502805,
|
||||||
|
description:"**"+req.body.issue.title+":**\n\n"+req.body.issue.body+"\n\n[Link to Issue]("+req.body.issue.html_url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}break;
|
||||||
|
default:{
|
||||||
|
console.log("Unknown action "+req.body.action+". Ignoring.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if(req.body.ref){
|
||||||
|
for(var commit of req.body.commits){
|
||||||
|
var filesAdded=commit.added.length
|
||||||
|
var filesRemoved=commit.removed.length
|
||||||
|
var filesModified=commit.modified.length
|
||||||
|
axios.post(process.env.GITEA_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:commit.author.username+" has pushed a new commit",
|
||||||
|
icon_url:"http://sig.projectdivar.com/assets/update.png"
|
||||||
|
},
|
||||||
|
color:17663,
|
||||||
|
description:"**Commit ID "+commit.id+"**\n\n"+commit.message+"\n"+(filesAdded>0?"\n"+filesAdded+" file"+(filesAdded==1?"":"s")+" added":"")+(filesRemoved>0?"\n"+filesRemoved+" file"+(filesRemoved==1?"":"s")+" removed":"")+(filesModified>0?"\n"+filesModified+" file"+(filesModified==1?"":"s")+" modified":"")+"\n\n[Link to Commit]("+commit.url+")",
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("Unknown webhook incoming. Ignoring.")
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
return axios.post(process.env.DISCORD_WEBHOOK,{embeds:[{
|
||||||
|
author:{
|
||||||
|
name:req.body.item_name,
|
||||||
|
icon_url:itemIcon
|
||||||
|
},
|
||||||
|
color:req.body.obtained==req.body.required?32768:Number(req.body.obtained)>0?20680:2172201,
|
||||||
|
description:"**"+req.body.username+"** "+(req.body.operation==="FINISH"?" has finished "+(req.body.finalcraft===true?"crafting ":"collecting ")+req.body.required+" __"+req.body.item_name+"__!":
|
||||||
|
req.body.operation==="INCREASE"?" has collected "+req.body.obtained+" / "+req.body.required+" __"+req.body.item_name+"__ (+"+(req.body.obtained-req.body.previous_amt)+")"
|
||||||
|
:" has set __"+req.body.item_name+"__ to "+req.body.obtained+" / "+req.body.required)+"\n\n[Sig Planner - Sig crafts all the things](http://projectdivar.com:3001)",
|
||||||
|
footer:{
|
||||||
|
"text":"Progress: "+((req.body.itemCount+req.body.obtained-req.body.previous_amt)/req.body.totalItemCount*100).toFixed(2)+"% ("+(req.body.itemCount+req.body.obtained-req.body.previous_amt)+"/"+req.body.totalItemCount+")"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})*/
|
||||||
|
})
|
||||||
|
|
||||||
var runInventoryScan = async()=>{
|
var runInventoryScan = async()=>{
|
||||||
for (var item of myInv) {
|
for (var item of myInv) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user