-
Notifications
You must be signed in to change notification settings - Fork 22
/
github-commit-status.php
executable file
·157 lines (138 loc) · 3.16 KB
/
github-commit-status.php
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env php
<?php
/**
* Utility to submit GitHub commit status to the
* GitHub API.
*
* @package Automattic/vip-go-ci
*/
declare(strict_types=1);
define( 'VIPGOCI_INCLUDED', true );
require_once __DIR__ . '/requires.php';
/*
* Configure PHP error reporting.
*/
vipgoci_set_php_error_reporting();
/*
* Recognized options, get options
*/
$options_recognized = array(
'env-options:',
'repo-owner:',
'repo-name:',
'github-token:',
'github-commit:',
'build-state:',
'build-description:',
'build-context:',
);
$options = getopt(
'',
$options_recognized
);
/*
* Options to remove of any sensitive
* detail when cleaned later.
*/
vipgoci_options_sensitive_clean(
null,
array(
'github-token',
)
);
/*
* Parse options
*/
vipgoci_option_array_handle(
$options,
'env-options',
array(),
null,
',',
false
);
vipgoci_options_read_env(
$options,
$options_recognized
);
/*
* Verify we have all the options
* we need.
*/
if (
( ! isset(
$options['repo-owner'],
$options['repo-name'],
$options['github-token'],
$options['github-commit'],
$options['build-state'],
$options['build-description'],
$options['build-context']
) )
||
(
isset( $options['help'] )
)
) {
print 'Usage: ' . $argv[0] . PHP_EOL .
PHP_EOL .
"\t" . '--repo-owner=STRING Specify repository owner, can be an organization' . PHP_EOL .
"\t" . '--repo-name=STRING Specify name of the repository' . PHP_EOL .
"\t" . '--github-token=STRING The access-token to use to communicate with GitHub' . PHP_EOL .
"\t" . '--github-commit=STRING Specify the exact commit to set state for' . PHP_EOL .
PHP_EOL .
"\t" . '--build-state=STRING Specify build state, one of: "pending", "failure", ' . PHP_EOL .
"\t" . ' and "success" are valid.' . PHP_EOL .
"\t" . '--build-description=STRING Specify description for end-user, displayed along with ' . PHP_EOL .
"\t" . ' state.' . PHP_EOL .
"\t" . '--build-context=STRING Specify context, a consistent identifier used across ' . PHP_EOL .
"\t" . ' all the build states' . PHP_EOL .
PHP_EOL .
"\t" . '--help Prints this message.' . PHP_EOL .
PHP_EOL .
'All options are mandatory.' . PHP_EOL;
exit( VIPGOCI_EXIT_USAGE_ERROR );
}
/*
* Verify that --build-state is of valid
* value.
*/
switch ( $options['build-state'] ) {
case 'pending':
case 'failure':
case 'success':
break;
default:
vipgoci_sysexit(
'Invalid parameter for --build-state, only "pending", "failure", and "success" are valid',
array(
'build-state' => $options['build-state'],
),
VIPGOCI_EXIT_USAGE_ERROR
);
}
/*
* Log that we are setting build
* status and set it.
*/
vipgoci_log(
'Setting build status for commit ...',
array(
'options' => vipgoci_options_sensitive_clean(
$options
),
)
);
vipgoci_github_status_create(
$options['repo-owner'],
$options['repo-name'],
$options['github-token'],
$options['github-commit'],
$options['build-state'],
'',
$options['build-description'],
$options['build-context']
);
vipgoci_log(
'Finished, exiting',
);