FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
checkman/scripts/travis.check at master · cppforlife/checkman · GitHub
cppforlife
/
checkman
Public
Notifications
You must be signed in to change notification settings
Fork
39
Star
85
Code
Issues
14
Pull requests
6
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
checkman
/
scripts
/
travis.check
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
197 lines (160 loc) · 4.34 KB
Breadcrumbs
checkman
/
scripts
/
travis.check
Copy path
File metadata and controls
executable file
·
197 lines (160 loc) · 4.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env ruby
require
"rubygems"
require
"json"
require
"time"
class
TravisBuildStatus
def
initialize
(
hash
)
@build_data
=
hash
end
def
id
@build_data
[
"id"
]
end
def
number
@build_data
[
"number"
]
end
def
state
# Possible states seen: created, started, finished
@build_data
[
"state"
]
end
def
branch
@build_data
[
"branch"
]
end
def
result
# Possible results seen: 1, 0, null
@build_data
[
"result"
]
end
def
for_branch?
(
branch_name
)
# Travis runs specs for pull request
# and marks them as event_type=pull_request
self
.
branch
==
branch_name
&&
@build_data
[
"event_type"
]
==
"push"
end
def
ok?
result
==
0
end
def
building?
state
!=
"finished"
end
def
duration
secs
=
if
@build_data
[
"duration"
]
@build_data
[
"duration"
]
elsif
started_at
Time
.
now
-
started_at
end
Time
.
at
(
secs
)
.
gmtime
.
strftime
(
"%R:%S"
)
if
secs
end
def
started_at
iso8601
=
@build_data
[
"started_at"
]
iso8601
&&
Time
.
parse
(
iso8601
)
end
def
formatted_started_at
time
=
started_at
time
&&
time
.
getlocal
.
strftime
(
"%I:%M%p %m/%d/%Y %Z"
)
end
def
last_commit_short_sha
@build_data
[
"commit"
]
[
0
..
5
]
end
def
last_commit_message
@build_data
[
"message"
]
end
def
as_json
(
options
=
{
}
)
{
:result
=>
ok?
,
:changing
=>
building?
,
:url
=>
"
#{
options
[
:repo_url
]
}
/builds/
#{
id
}
"
,
:info
=>
[
[
:Build
,
number
]
,
[
:Duration
,
duration
]
,
[
:Started
,
formatted_started_at
]
,
[
"-"
,
""
]
,
[
:Branch
,
branch
]
,
[
:State
,
state
]
,
[
:SHA
,
last_commit_short_sha
]
,
[
:Message
,
last_commit_message
]
]
}
end
def
to_json
(
*
)
JSON
.
dump
(
as_json
)
end
end
class
TravisBranchStatus
def
initialize
(
repo_url
,
build_statuses
)
@repo_url
=
repo_url
@build_statuses
=
build_statuses
raise
StandardError
,
"Status for branch is not available"
\
unless
last_build_status
end
def
ok?
if
last_build_status
.
building?
&&
last_done_building_status
last_done_building_status
.
ok?
else
last_build_status
.
ok?
end
end
def
as_json
(
*
)
last_build_status
.
as_json
(
{
:repo_url
=>
@repo_url
}
)
.
tap
do
|
hash
|
hash
[
:result
]
=
ok?
end
end
def
to_json
(
*
)
JSON
.
dump
(
as_json
)
end
def
last_build_status
@build_statuses
.
first
end
def
last_done_building_status
# Travis does not wait for running/starting builds
# to finish before running/starting new builds,
# so 2nd build does not necessarily represent last result.
@build_statuses
[
1
..-
1
]
.
detect
{
|
bs
| !
bs
.
building?
}
end
end
class
TravisRepoStatus
def
initialize
(
repo_url
,
json
)
@repo_url
=
repo_url
@build_statuses
=
JSON
.
parse
(
json
)
.
map
{
|
d
|
TravisBuildStatus
.
new
(
d
)
}
rescue
JSON
::
ParserError
raise
RuntimeError
,
"invalid json: '
#{
json
}
'"
end
def
status_for_branch
(
branch_name
)
build_statuses
=
@build_statuses
.
select
{
|
bs
|
bs
.
for_branch?
(
branch_name
)
}
TravisBranchStatus
.
new
(
@repo_url
,
build_statuses
)
end
end
class
Travis
def
initialize
(
repo_owner
,
repo_name
,
repo_branch
=
"master"
,
repo_token
=
nil
)
raise
ArgumentError
"repo_owner must not be nil"
\
unless
@repo_owner
=
repo_owner
raise
ArgumentError
"repo_name must not be nil"
\
unless
@repo_name
=
repo_name
raise
ArgumentError
"repo_branch must not be nil"
\
unless
@repo_branch
=
repo_branch
@repo_token
=
repo_token
end
def
latest_status
TravisRepoStatus
.
new
(
repo_url
,
http_get
(
builds_url
)
)
\
.
status_for_branch
(
@repo_branch
)
end
private
def
repo_url
domain
=
@repo_token
?
"magnum.travis-ci.com"
:
"travis-ci.org"
"https://
#{
domain
}
/
#{
@repo_owner
}
/
#{
@repo_name
}
"
end
def
builds_url
# Since TravisCI does not provide api to fetch build history for
# a specific branch we have to use repo build history and hope
# that checked branch does not get pushed off the first N builds.
domain
=
@repo_token
?
"api.travis-ci.com"
:
"api.travis-ci.org"
token
=
@repo_token
?
"token=
#{
@repo_token
}
"
:
""
"https://
#{
domain
}
/repositories/
#{
@repo_owner
}
/
#{
@repo_name
}
/builds.json?
#{
token
}
"
end
def
http_get
(
url
)
curl
=
"curl -s -A
\"
CheckmanTravis (Hostname: $HOSTNAME)
\"
'
#{
url
}
'"
`
#{
curl
}
`
.
tap
{
|
o
| $stderr
.
puts
curl
,
o
}
end
end
puts
Travis
.
new
(
*
ARGV
)
.
latest_status
.
to_json
if
__FILE__
== $0
Back
|
FazBrowse Home
|
New Git URL