line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::GHPT::WorkSubmitter::Role::Question; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7777
|
use App::GHPT::Wrapper::OurMoose::Role; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
18
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.001000'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
156
|
use Term::CallEditor qw( solicit ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
85
|
|
8
|
1
|
|
|
1
|
|
7
|
use Term::Choose qw( choose ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
704
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
requires 'ask'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has changed_files => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'App::GHPT::WorkSubmitter::ChangedFiles', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
|
sub ask_question ( $self, $question, @responses ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $choice = choose( |
20
|
|
|
|
|
|
|
[ |
21
|
|
|
|
|
|
|
@responses, |
22
|
|
|
|
|
|
|
'Launch Editor' |
23
|
|
|
|
|
|
|
], |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
prompt => $question, |
26
|
0
|
0
|
0
|
|
|
|
clear_screen => $ENV{'SUBMIT_WORK_CLEAR'} // 0 |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
) or exit; # user hit 'q' or ctrl-d to stop |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
return $self->format_qa_markdown( $question, $choice ) |
31
|
|
|
|
|
|
|
unless $choice eq 'Launch Editor'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# todo: It would be nice if the notes persisted to disk for a given PT so |
34
|
|
|
|
|
|
|
# that I could ctrl-c out of a later question and still not have to retype |
35
|
|
|
|
|
|
|
# previously asked questions. That's a task for another day however. |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $prompt = <<"ENDOFTEXT"; |
38
|
|
|
|
|
|
|
$question |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Complete your answer below the line in markdown. |
41
|
|
|
|
|
|
|
--- |
42
|
|
|
|
|
|
|
ENDOFTEXT |
43
|
0
|
|
|
|
|
|
my $fh = solicit($prompt); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $answer = do { local $/ = undef; <$fh> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$answer =~ s/\A\Q$prompt//; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $self->format_qa_markdown( $question, $answer ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
52
|
0
|
|
|
0
|
|
|
sub _trim ($text) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return $text =~ s/\A\s+//r =~ s/\s+\z//r; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
## use critic |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
0
|
|
sub format_qa_markdown ( $self, $question, $answer ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return <<"ENDOFMARKDOWN"; |
59
|
|
|
|
|
|
|
### Question ### |
60
|
0
|
|
|
|
|
|
@{[ _trim( $question )]} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
### Answer ### |
63
|
0
|
|
|
|
|
|
@{[ _trim( $answer ) ]} |
64
|
|
|
|
|
|
|
ENDOFMARKDOWN |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ABSTRACT: Role for writing interactive questions about the commits |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=encoding UTF-8 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
App::GHPT::WorkSubmitter::Role::Question - Role for writing interactive questions about the commits |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 VERSION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
version 1.001000 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
package App::GHPT::WorkSubitter::Question::WarnAboutPasswordFile; |
88
|
|
|
|
|
|
|
use App::GHPT::Wrapper::OurMoose; |
89
|
|
|
|
|
|
|
with 'App::GHPT::WorkSubmitter::Role::Question'; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub ask($self) { |
92
|
|
|
|
|
|
|
# skip the question unless there's a password file |
93
|
|
|
|
|
|
|
return unless $self->changed_files->changed_files_match(qr/password/); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# ask the user if that's okay |
96
|
|
|
|
|
|
|
return $self->ask_question(<<'ENDOFTEXT',"I'm okay with the risk"); |
97
|
|
|
|
|
|
|
You've committed a file with a name matching 'password'. Are you nuts? |
98
|
|
|
|
|
|
|
ENDOFTEXT |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This role allows you to write questions to ask someone when creating pull |
107
|
|
|
|
|
|
|
request. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
You want to create these questions classes in the |
110
|
|
|
|
|
|
|
C<App::GHPT::WorkSubmitter::Question::*> namespace where |
111
|
|
|
|
|
|
|
L<App::GHPT::WorkSubmitter::Questioner> will automatically detect them and ask |
112
|
|
|
|
|
|
|
them each time C<gh-pt.pl> is run. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Each class must supply an C<ask> method which should prompt the user as needed |
115
|
|
|
|
|
|
|
and return any markdown to be placed in the pull request body. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 changed_files |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The files that have changed in this branch. This is the primary attribute |
122
|
|
|
|
|
|
|
you want to examine. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 $question->ask_question($question, @optional_responses) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Interactively ask a question and return markdown suitable for including in the |
129
|
|
|
|
|
|
|
pull request body. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The question that should be asked must be passed as the first argument, and |
132
|
|
|
|
|
|
|
all other arguments are treated as stock answers the user can select when |
133
|
|
|
|
|
|
|
asked the question. The user will also have a final option C<Launch Editor> |
134
|
|
|
|
|
|
|
which will launch their editor and allow them free-form text input. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SUPPORT |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Bugs may be submitted through L<https://github.com/maxmind/App-GHPT/issues>. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHORS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Mark Fowler <mark@twoshortplanks.com> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This software is Copyright (c) 2021 by MaxMind, Inc. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This is free software, licensed under: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |