forked from nvie/gitflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGitFlowCommon.pm
More file actions
126 lines (103 loc) · 3.23 KB
/
GitFlowCommon.pm
File metadata and controls
126 lines (103 loc) · 3.23 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use MIME::Base64;
use LWP::UserAgent;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
use JIRA::Client;
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
my $user = trim(`git config --get gitflow.ld.username`);
my $encoded_password = trim(`git config --get gitflow.ld.password`);
my $password = trim(decode_base64($encoded_password));
my $jira_base_url = 'http://jira/';
my %workflow_statuses = (
'Open' => 1,
'In Progress' => 3,
'Code Review' => 10011,
'Resolved' => 5,
'Closed' => 6
);
my %workflow_resolutions = (
'Fixed' => 1,
'Won\'t Fix' => 2,
'Duplicate' => 3,
'Incomplete' => 4,
'Can\'t Reproduce' => 5,
'Delayed' => 6,
'Invalid' => 10
);
my $jira = JIRA::Client->new( $jira_base_url, $user, $password );
#my $issue = eval { $jira->getIssue("MOBCODEBASE-353") };
#print "Issue: " . Dumper($issue) . "\n";
#print "Resolution: " . $issue->{resolution} . "\n";
#print "Status: " . $issue->{status} . "\n";
#print Dumper($jira->get_statuses());
sub warnTicketInvalid() {
die "\nERROR: Feature name is not a valid jira-ticket.\n\n";
}
sub warnTicketAlreadyWorking() {
print "\nWARNING! Feature is already in progress.\n\n";
}
sub warnTicketDone() {
print "\nWARNING! You are trying to work on finished ticket.\n\n";
}
sub warnTicketNotWorking() {
print "\nWARNING! You are not working on this feature by now.\n\n";
}
sub warnTicketNotFinished() {
print "\nWARNING! You are finishing feature that is not resolved yet.\n\n";
}
# start new feature
sub startFeature {
my $newFeature = $_[0];
my $curFeature = trim(`git config --get gitflow.prefix.feature.issue`);
if ( "$curFeature" ne "" ) {
# get the current ticket
my $curIssue = eval { $jira->getIssue($curFeature) };
# move issue over the workflow (stop progress)
if ($curIssue->{status} == $workflow_statuses{'In Progress'}) {
$jira->progress_workflow_action_safely(
$curIssue,
'Stop Progress'
);
}
}
# get the new ticket
my $newIssue = eval { $jira->getIssue($newFeature) };
my $assignee = $newIssue->{assignee};
# check tiket exists
warnTicketInvalid() if $@;
# check ticket is opened
warnTicketAlreadyWorking() if ($newIssue->{status} == $workflow_statuses{'In Progress'});
warnTicketDone() if ($newIssue->{status} != $workflow_statuses{'Open'} && $newIssue->{status} != $workflow_statuses{'In Progress'});
# remember ticket & assignee
system("git config gitflow.prefix.feature.issue $newFeature");
system("git config gitflow.prefix.feature.assignee $assignee");
if ($newIssue->{status} == $workflow_statuses{'Open'}) {
# move issue over the workflow (start progress)
$jira->progress_workflow_action_safely(
$newIssue,
'Start Progress'
);
}
}
# finish current feature
sub finishFeature {
my $feature = $_[0];
# get the ticket
my $issue = eval { $jira->getIssue($feature) };
# check tiket exists
warnTicketInvalid() if $@;
# check ticket is resolved
warnTicketNotFinished() if ($issue->{status} != $workflow_statuses{'Resolved'} && $issue->{status} != $workflow_statuses{'Closed'});
# clear config
system("git config --unset gitflow.prefix.feature.issue");
system("git config --unset gitflow.prefix.feature.assignee");
}