Any Gitea users sending webhooks to Rocket.Chat? Share your scripts here

Let me start with my simple script, here’s the output

09%20PM

class Script {
  /**
   * @params {object} request
   */
  process_incoming_request({ request }) {
    var i_message; var message = ''; var text;
    repository = request.content['repository']['full_name'];
    
    for (i_message = 0; i_message < request.content.commits.length; i_message++) { 
      message += "[#"+request.content.commits[i_message]['id'].substring(0,10)+"]("+request.content.commits[i_message]['url']+")" + ': ' + request.content.commits[i_message]['message'];
    }

    if (i_message > 1) {
      text = i_message + ' commits pushed to ' + repository;
    } else {
      text = '1 commits pushed to ' + repository;
    }
    
    return {
      content:{
        text: text, 
         "attachments": [{
           "title": 'Compare All',
           "title_link": request.content['compare_url'],
           "text": message,
        }]
       }
    };
  }
}

Hello,
Almost working on my setup : I only had to remove the title link as Gitea provides an empty ‘compare_url’.

I also added pusher’s name in text var :

if (i_message > 1) {
  text = i_message + ' commits pushed to ' + repository + 'by ' + request.content['pusher']['full_name'];
} else {
  text = '1 commit pushed to ' + repository + 'by ' + request.content['pusher']['full_name'];
} 

Thanks for sharing !

1 Like

Would be awesome to see this created as a Rocket.Chat App so people could easily install on their server! :slight_smile:

1 Like

If there was more time in the day :slight_smile: feel free to make it happen!


I write scripts to fit all notification here
Hope u enjoy it !

If you wish to convert this into a Rocket.Chat App and distribute via our Marketplace, that would be fantastic!