Bir projenin başarısız çalıştırmalarını listele
Bir projenin başarısız çalıştırmalarını listeler ve her biri için test adını, bitiş zamanını ve özetini yazdırır.
#!/usr/bin/env bash
# Print the failed runs of project 42, newest first, following next until null. Needs curl 7.76+ and jq.
set -euo pipefail
origin="https://optisway.com"
auth="Authorization: Bearer $OPTISWAY_API_KEY"
fail() { echo "$1" | jq -r '"\(.error): \(.message)"' >&2; exit 1; }
path="/api/v1/runs?project=42&status=failed&limit=50"
while [ -n "$path" ]; do
page=$(curl --fail-with-body -sS "$origin$path" -H "$auth") || fail "$page"
echo "$page" | jq -r '.items[] | "\(.testName) \(.finishedAt) \(.summary // "")"'
path=$(echo "$page" | jq -r '.next // empty')
done// Node.js 18+: save as list-failures.mjs and run `node list-failures.mjs`
const origin = "https://optisway.com";
const headers = { Authorization: `Bearer ${process.env.OPTISWAY_API_KEY}` };
// `next` is the same path with before=<last id>, or null on the last page.
let path = "/api/v1/runs?project=42&status=failed&limit=50";
while (path) {
const response = await fetch(origin + path, { headers });
const page = await response.json();
if (!response.ok) {
console.error(`${response.status} ${page.error}: ${page.message}`);
process.exit(1);
}
for (const run of page.items) console.log(run.testName, run.finishedAt, run.summary);
path = page.next;
}# pip install requests
import os
import sys
import requests
ORIGIN = "https://optisway.com"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['OPTISWAY_API_KEY']}"
# "next" is the same path with before=<last id>, or None on the last page.
path = "/api/v1/runs?project=42&status=failed&limit=50"
while path:
response = session.get(ORIGIN + path, timeout=30)
page = response.json()
if not response.ok:
print(f"{response.status_code} {page['error']}: {page['message']}", file=sys.stderr)
sys.exit(1)
for run in page["items"]:
print(run["testName"], run["finishedAt"], run["summary"], sep=" ")
path = page["next"]require "json"
require "net/http"
require "uri"
ORIGIN = "https://optisway.com"
KEY = ENV.fetch("OPTISWAY_API_KEY")
# "next" is the same path with before=<last id>, or nil on the last page.
path = "/api/v1/runs?project=42&status=failed&limit=50"
while path
uri = URI(ORIGIN + path)
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer #{KEY}"
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
page = JSON.parse(response.body)
unless response.is_a?(Net::HTTPSuccess)
warn "#{response.code} #{page["error"]}: #{page["message"]}"
exit 1
end
page["items"].each do |run|
puts [run["testName"], run["finishedAt"], run["summary"]].join(" ")
end
path = page["next"]
end<?php
const ORIGIN = "https://optisway.com";
// "next" is the same path with before=<last id>, or null on the last page.
$path = "/api/v1/runs?project=42&status=failed&limit=50";
while ($path !== null) {
$curl = curl_init(ORIGIN . $path);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("OPTISWAY_API_KEY")],
]);
$page = json_decode((string) curl_exec($curl), true);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
if ($status < 200 || $status >= 300) {
fwrite(STDERR, "$status " . ($page["error"] ?? "request_failed") . ": "
. ($page["message"] ?? curl_error($curl)) . "\n");
exit(1);
}
foreach ($page["items"] as $run) {
echo $run["testName"], " ", $run["finishedAt"], " ", $run["summary"], "\n";
}
$path = $page["next"];
}// Java 11+: save as Main.java and run `java Main.java`
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
static final String ORIGIN = "https://optisway.com";
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
// "next" is the same path with before=<last id>, or null on the last page.
String path = "/api/v1/runs?project=42&status=failed&limit=50";
while (path != null) {
HttpRequest request = HttpRequest.newBuilder(URI.create(ORIGIN + path))
.header("Authorization", "Bearer " + System.getenv("OPTISWAY_API_KEY"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
String page = response.body();
if (response.statusCode() >= 300) {
System.err.println(response.statusCode() + " " + field(page, "error") + ": "
+ field(page, "message"));
System.exit(1);
}
// Run fields come in a fixed order (testName before finishedAt and summary); a JSON library such as
// Jackson or Gson reads them properly.
Matcher names = Pattern.compile("\"testName\"\\s*:").matcher(page);
while (names.find()) {
String run = page.substring(names.start());
System.out.println(field(run, "testName") + " " + field(run, "finishedAt") + " "
+ field(run, "summary"));
}
path = field(page.substring(page.lastIndexOf("\"next\"")), "next");
}
}
/** The first string value of a JSON key (dependency-free; Jackson or Gson parse JSON properly). */
static String field(String json, String key) {
Matcher match = Pattern.compile("\"" + key + "\"\\s*:\\s*(?:\"((?:[^\"\\\\]|\\\\.)*)\"|null)")
.matcher(json);
return match.find() ? match.group(1) : null;
}
}package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
const origin = "https://optisway.com"
type page struct {
Items []struct {
TestName string `json:"testName"`
FinishedAt string `json:"finishedAt"`
Summary string `json:"summary"`
} `json:"items"`
Next *string `json:"next"`
Error string `json:"error"`
Message string `json:"message"`
}
func main() {
// next is the same path with before=<last id>, or null on the last page.
path := "/api/v1/runs?project=42&status=failed&limit=50"
for path != "" {
req, err := http.NewRequest(http.MethodGet, origin+path, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("OPTISWAY_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
var p page
err = json.NewDecoder(resp.Body).Decode(&p)
resp.Body.Close()
if err != nil {
panic(err)
}
if resp.StatusCode >= 300 {
fmt.Fprintf(os.Stderr, "%d %s: %s\n", resp.StatusCode, p.Error, p.Message)
os.Exit(1)
}
for _, run := range p.Items {
fmt.Println(run.TestName, run.FinishedAt, run.Summary)
}
path = ""
if p.Next != nil {
path = *p.Next
}
}
}// .NET 8: `dotnet new console`, replace Program.cs with this file, then `dotnet run`
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
const string Origin = "https://optisway.com";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("OPTISWAY_API_KEY"));
// "next" is the same path with before=<last id>, or null on the last page.
string? path = "/api/v1/runs?project=42&status=failed&limit=50";
while (path is not null)
{
using var response = await client.GetAsync(Origin + path);
var page = await response.Content.ReadFromJsonAsync<JsonElement>();
if (!response.IsSuccessStatusCode)
{
var error = page.GetProperty("error");
var message = page.GetProperty("message");
Console.Error.WriteLine($"{(int)response.StatusCode} {error}: {message}");
return 1;
}
foreach (var run in page.GetProperty("items").EnumerateArray())
{
Console.WriteLine(string.Join(" ",
run.GetProperty("testName"), run.GetProperty("finishedAt"), run.GetProperty("summary")));
}
path = page.GetProperty("next").GetString();
}
return 0;