This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommit_hook.pl
executable file
·76 lines (66 loc) · 2.58 KB
/
commit_hook.pl
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/perl
# Author: Fiorentino Salvatore
# All fields are optional, to define a commit a pull_request commit is mandatory to write 'pull_request'
# Syntax: git commit -m ".* pull_request({fields})? .*"
# Example:
# git commit -m"This is a commit pull_request{
# title=title test:
# body=body pull request:
# reviewer=instafiore:
# }"
$regex = 'Author:\s+(?<author_username>[\w\-]+)\s+.+\nDate:\s+(?<day>\w+)\s(?<mounth>\w+)\s(?<day_number>\w+)\s(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})\s(?<year>\d{4}).+\n+(?<message>(.|\n)+?)\ndiff';
$regex2 = 'Author:\s+(?<author_username>[\w\-]+)\s+.+\nDate:\s+(?<day>\w+)\s(?<mounth>\w+)\s(?<day_number>\w+)\s(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})\s(?<year>\d{4}).+\n+(?<message>(.|\n)+)';
$regex_inner_message_pull_request = '(((?<=[\s+])pull_request{\n*\s*(?<inner_1>(.|\n)*?)\})|(^pull_request{\n*\s*(?<inner_2>(.|\n)*?)\}))';
$regex_default_pull_request = '((\s+pull_request(?!{))|(^pull_request(?!{)))';
$sha = shift ;
$output_git_log = `git show $sha` ;
if($output_git_log =~ /$regex/gm or $output_git_log =~ /$regex2/gm){
$author_username = $+{author_username};
$day = $+{day};
$mounth = $+{mounth};
$day_number = $+{day_number};
$hour = $+{hour};
$minute = $+{minute};
$second = $+{second};
$year = $+{year};
$message = $+{message};
$title = "$author_username made a pull request";
$body = "Hey I'm $author_username and I would like to merge my branch to master";
$delete_branch = 'false' ;
$reviewer = "";
if($message =~ /$regex_inner_message_pull_request/gm){
$inner ;
if($+{inner_1}){
$inner = $+{inner_1} ;
}else{
$inner = $+{inner_2} ;
}
@split = split(":", $inner);
for(@split){
s/^\s+|\s+$//g;
@map = split("=");
if($map[0] eq 'title'){
$title = $map[1];
}elsif($map[0] eq 'body'){
$body = $map[1];
}elsif($map[0] eq 'delete_branch'){
$delete_branch = $map[1] ;
}elsif($map[0] eq 'reviewer'){
$reviewer = $map[1];
}
}
}elsif(!($message =~ /$regex_default_pull_request/gm)){
print("status=failed");
exit ;
# die "not a pull_request commit!\n";
}
print("title=$title\n");
print("body=$body\n");
#print("delete_branch=$delete_branch\n");
print("reviewer=$reviewer\n");
print("status=success");
}else{
print("status=failed");
exit ;
# die "not a pull_request commit!\n";
}