summary refs log tree commit diff
path: root/etc/gitea2mastodon.rb
blob: d2eaafd0a40ac49a967de9887a07deca2e57b555 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env ruby
require 'cgi'
require 'json'
require 'mastodon'

require_relative 'secret'

cgi = CGI.new
begin
	payload = JSON.parse(cgi.params['payload'].first)
rescue
	cgi.out('status' => 'BAD_REQUEST', 'type' => 'text/plain') { 'bad' }
	exit
end
if payload['secret'] != GITEA_SECRET
	cgi.out('status' => 'FORBIDDEN', 'type' => 'text/plain') { 'no' }
	exit
end

client = Mastodon::REST::Client.new(
	base_url: MASTODON_URL,
	bearer_token: MASTODON_TOKEN,
)

payload['commits'].reverse.each do |commit|
	message = commit['message']
		.split("\n\n")
		.map {|p| p.split("\n").join(' ') }
		.join("\n")
	client.create_status("🚽 #{message}\n#{commit['url']}")
end

cgi.out('text/plain') { 'ok' }