summary refs log tree commit diff
path: root/etc/gitea2mastodon.rb
blob: 950a881ba05569019dcd187e1d90e1b930b36c43 (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
34
#!/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|
	next unless commit['message'].include?("\n\n")
	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' }
391087d8d667327099&follow=1'>Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe