Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Bug 4622) Feature/bug4622 hooks #1

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bin/github-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

username=$1;
password=$2;
domain=$3;

if [ -z "$username" ]
then
echo "Github username: "
read -r username
fi

if [ -z "$password" ]
then
echo "Github password: "
read -r -s password
fi

if [ -z "$domain" ]
then
echo "Your SITEROOT: (http://www.blah.com)"
read -r domain
fi

if [ -z "$username" -o -z "$password" -o -z "$domain" ]
then
echo "Incomplete information. Make sure you've entered the Github username & password, and your siteroot" >&2
exit 1
fi

url="$domain/interface/github"
curl -i -v -u "$username:$password" -d "{\"name\":\"web\",\"config\":{\"url\":\"$url\"},\"events\":[\"push\",\"pull_request\"]}" "https://api.github.com/repos/$username/dw-nonfree/hooks"
12 changes: 6 additions & 6 deletions bin/upgrading/s2layers.dat
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
################################################################
# base filename layer type parent

siteviews/themes-local theme+ siteviews/layout
siteviews/themes theme+ siteviews/layout

bannering/themes-local theme+ bannering/layout
bannering/themes theme+ bannering/layout

colorside/themes-local theme+ colorside/layout
colorside/themes theme+ colorside/layout

modish/themes-local theme+ modish/layout
modish/themes theme+ modish/layout

modular/themes-local theme+ modular/layout
modular/themes theme+ modular/layout

practicality/themes-local theme+ practicality/layout
practicality/themes theme+ practicality/layout

sundaymorning/layout layout core2
sundaymorning/themes theme+ sundaymorning/layout
Expand Down
103 changes: 103 additions & 0 deletions cgi-bin/DW/Controller/Interface/Github.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/perl
#
# DW::Controller::Interface::Github.pm
#
# DW github webhook code
#
# Authors:
# Afuna <coder.dw@afunamatata.com>
# Pau Amma <pauamma@dreamwidth.org>
#
# Copyright (c) 2012 by Dreamwidth Studios, LLC.
#
# This program is NOT free software or open-source; you can use it as an
# example of how to implement your own site-specific extensions to the
# Dreamwidth Studios open-source code, but you cannot use it on your site
# or redistribute it, with or without modifications.

use strict;
use warnings;

use DW::Routing;
use JSON ();
use XMLRPC::Lite;

DW::Routing->register_string( "/interface/github", \&hooks_handler,
app => 1, methods => { POST => 1 } );

sub hooks_handler {
my $r = DW::Request->get;

# parse out the payload
my $payload = JSON::jsonToObj( $r->post_args->{payload} );

my $hook_type = exists $payload->{pull_request} ? "pull_request" :
exists $payload->{commits} ? "push" :
"";

my %table = (
pull_request => [ sub {
my $payload = $_[0];

my $bugzilla = $LJ::GITHUB{bugzilla};
my $username = $bugzilla->{username};
my $password = $bugzilla->{password};
my $server = $bugzilla->{server};
return unless defined $username && defined $password && defined $server;

my $pull_request = $payload->{pull_request};

# we're looking for anything that looks like a bug id
# in the form of: "close / fix / address bug 123, 456, and 789"
my $pull_text = "$pull_request->{title} $pull_request->{body}";
my ( $closes, $bugs ) =
( $pull_text =~ /(?:(close|fix|address)e?(?:s|d)? )?bugs?:? *([\d ,\+&#and]+)/i );
my @bug_ids = grep { $_ + 0 } split( /(\d+)/, $bugs );
return unless @bug_ids;

my $msg = sprintf( "Pull Request %d: %s (%s)\n",
$payload->{number},
$payload->{action},
$pull_request->{user}->{login}
);

$msg .= sprintf( "%s\n\n%s\n%s",
$pull_request->{html_url},
$pull_request->{title},
$pull_request->{body}
);

my $xmlrpc = XMLRPC::Lite->new;
$xmlrpc->proxy(
"http://$server/xmlrpc.cgi",
agent => "$LJ::SITENAME Changelog Hook ($LJ::ADMIN_EMAIL)"
);

foreach my $id ( @bug_ids ) {
my $res = $xmlrpc->call( "Bug.add_comment", {
id => $id, comment => $msg,
Bugzilla_login => $username,
Bugzilla_password => $password
} );
}
} ],
push => [ sub {
# post to changelog
warn "commits hook: post to changelog";
}, sub {
# comment on zilla
warn "commits hook: post to zilla";
}, sub {
# mark zilla as resolved
warn "commits hook: mark as resolved";
} ],
);

foreach my $action ( @{$table{$hook_type}} ) {
$action->( $payload );
}

return $r->OK;
}

1;
14 changes: 14 additions & 0 deletions etc/config-local.pl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@
end_time => "Inf",
},
);

%GITHUB = (
bugzilla => {
username => '',
password => '',
server => 'bugs.dwscoalition.org',
},
changelog => {
username => '',
password => '',
}
);


}

1;