gogs.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class Script {
  2. process_incoming_request({ request }) {
  3. var c = request.content
  4. // console is a global helper to improve debug
  5. console.log(c)
  6. var commits = []
  7. for(var i=0; i<c.commits.length; i++) {
  8. var commit = c.commits[i]
  9. commits.push({
  10. title: commit.message,
  11. title_link: commit.url,
  12. author_name: commit.author.name,
  13. fields: [{
  14. title: "Timestamp",
  15. value: commit.timestamp
  16. }, {
  17. title: "Hash",
  18. value: commit.id
  19. }]
  20. })
  21. }
  22. var commit_text = "commit"
  23. if (c.length > 1) {
  24. commit_text += "s"
  25. }
  26. return {
  27. content: {
  28. alias: c.pusher.full_name,
  29. icon_url: c.pusher.avatar_url,
  30. text: c.commits.length + " " + commit_text + " pushed to [" + c.repository.full_name + "](" + c.repository.html_url + ") at " + c.ref,
  31. attachments: commits
  32. }
  33. }
  34. return {
  35. error: {
  36. success: false,
  37. message: 'Error'
  38. }
  39. }
  40. }
  41. }