|
145 | 145 | git -C /tmp/repo add . |
146 | 146 | git config --global user.email test@localhost |
147 | 147 | git config --global user.name test |
| 148 | +
|
| 149 | + # Create initial commit |
148 | 150 | git -C /tmp/repo commit -m 'Initial import' |
149 | 151 | git -C /tmp/repo remote add origin gitea@machine:root/repo |
150 | | - GIT_SSH_COMMAND='ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no' \ |
151 | | - git -C /tmp/repo push origin master |
| 152 | + export GIT_SSH_COMMAND='ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no' |
| 153 | + git -C /tmp/repo push origin master |
| 154 | + git -C /tmp/repo log >&2 |
| 155 | +
|
| 156 | + # Create PR branch |
| 157 | + git -C /tmp/repo checkout -b pr |
| 158 | + git -C /tmp/repo commit --allow-empty -m 'Additional change' |
| 159 | + git -C /tmp/repo push origin pr |
152 | 160 | git -C /tmp/repo log >&2 |
153 | 161 | ''; |
154 | 162 |
|
|
185 | 193 | cat >data.json <<EOF |
186 | 194 | { |
187 | 195 | "description": "Trivial", |
188 | | - "checkinterval": "60", |
| 196 | + "checkinterval": "20", |
189 | 197 | "enabled": "1", |
190 | 198 | "visible": "1", |
191 | 199 | "keepnr": "1", |
|
199 | 207 | "gitea_repo_name": {"value": "repo", "type": "string"}, |
200 | 208 | "gitea_repo_owner": {"value": "root", "type": "string"}, |
201 | 209 | "gitea_status_repo": {"value": "git", "type": "string"}, |
202 | | - "gitea_http_url": {"value": "http://localhost:3001", "type": "string"} |
| 210 | + "gitea_http_url": {"value": "http://localhost:3001", "type": "string"}, |
| 211 | + "pulls": { |
| 212 | + "type": "giteapulls", |
| 213 | + "value": "localhost:3001 root repo http", |
| 214 | + "emailresponsible": false |
| 215 | + } |
203 | 216 | } |
204 | 217 | } |
205 | 218 | EOF |
|
227 | 240 | }; |
228 | 241 |
|
229 | 242 | smallDrv = pkgs.writeText "jobset.nix" '' |
230 | | - { trivial = builtins.derivation { |
231 | | - name = "trivial"; |
232 | | - system = "${system}"; |
233 | | - builder = "/bin/sh"; |
234 | | - allowSubstitutes = false; |
235 | | - preferLocalBuild = true; |
236 | | - args = ["-c" "echo success > $out; exit 0"]; |
| 243 | + { pulls, ... }: |
| 244 | +
|
| 245 | + let |
| 246 | + genDrv = name: builtins.derivation { |
| 247 | + inherit name; |
| 248 | + system = "${system}"; |
| 249 | + builder = "/bin/sh"; |
| 250 | + allowSubstitutes = false; |
| 251 | + preferLocalBuild = true; |
| 252 | + args = ["-c" "echo success > $out; exit 0"]; |
237 | 253 | }; |
238 | | - } |
| 254 | +
|
| 255 | + prs = builtins.fromJSON (builtins.readFile pulls); |
| 256 | + prJobNames = map (n: "pr-''${n}") (builtins.attrNames prs); |
| 257 | + prJobset = builtins.listToAttrs ( |
| 258 | + map ( |
| 259 | + name: { |
| 260 | + inherit name; |
| 261 | + value = genDrv name; |
| 262 | + } |
| 263 | + ) prJobNames |
| 264 | + ); |
| 265 | + in { |
| 266 | + trivial = genDrv "trivial"; |
| 267 | + } // prJobset |
239 | 268 | ''; |
240 | 269 | in |
241 | 270 | '' |
|
279 | 308 | + '| jq .buildstatus | xargs test 0 -eq' |
280 | 309 | ) |
281 | 310 |
|
| 311 | + machine.sleep(3) |
| 312 | +
|
282 | 313 | data = machine.succeed( |
283 | | - 'curl -Lf -s "http://localhost:3001/api/v1/repos/root/repo/statuses/$(cd /tmp/repo && git show | head -n1 | awk "{print \\$2}")" ' |
| 314 | + 'curl -Lf -s "http://localhost:3001/api/v1/repos/root/repo/statuses/$(cd /tmp/repo && git show master | head -n1 | awk "{print \\$2}")?sort=leastindex" ' |
284 | 315 | + "-H 'Accept: application/json' -H 'Content-Type: application/json' " |
285 | 316 | + f"-H 'Authorization: token ${api_token}'" |
286 | 317 | ) |
287 | 318 |
|
288 | 319 | response = json.loads(data) |
289 | 320 |
|
290 | | - assert len(response) == 2, "Expected exactly three status updates for latest commit (queued, finished)!" |
| 321 | + assert len(response) == 2, "Expected exactly two status updates for latest commit (queued, finished)!" |
291 | 322 | assert response[0]['status'] == "success", "Expected finished status to be success!" |
292 | 323 | assert response[1]['status'] == "pending", "Expected queued status to be pending!" |
293 | 324 |
|
| 325 | + # giteapulls test |
| 326 | +
|
| 327 | + machine.succeed( |
| 328 | + "curl --fail -X POST http://localhost:3001/api/v1/repos/root/repo/pulls " |
| 329 | + + "-H 'Accept: application/json' -H 'Content-Type: application/json' " |
| 330 | + + f"-H 'Authorization: token ${api_token}'" |
| 331 | + + ' -d \'{"title":"Test PR", "base":"master", "head": "pr"}\''' |
| 332 | + ) |
| 333 | +
|
| 334 | + machine.wait_until_succeeds( |
| 335 | + 'curl -Lf -s http://localhost:3000/build/2 -H "Accept: application/json" ' |
| 336 | + + '| jq .buildstatus | xargs test 0 -eq' |
| 337 | + ) |
| 338 | +
|
294 | 339 | machine.shutdown() |
295 | 340 | ''; |
296 | 341 | }); |
|
0 commit comments