-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
587 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.github.stianst.gh; | ||
|
||
import io.github.stianst.gh.utils.Client; | ||
import org.kohsuke.github.GHWorkflowJob; | ||
import org.kohsuke.github.GHWorkflowRun; | ||
import org.kohsuke.github.GitHub; | ||
import org.kohsuke.github.PagedIterable; | ||
|
||
import java.io.IOException; | ||
import java.util.*; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class RunningJobs { | ||
|
||
public static void main(String[] args) throws IOException { | ||
|
||
Map<String, Integer> queued = new HashMap<>(); | ||
Map<String, Integer> running = new HashMap<>(); | ||
|
||
String repo = "cncf/keycloak-testing"; | ||
// String repo = "keycloak/keycloak"; | ||
|
||
GitHub gitHub = Client.getInstance().gitHub(); | ||
PagedIterable<GHWorkflowRun> list = gitHub.getRepository(repo).queryWorkflowRuns().created(">=2024-09-20").list(); | ||
for (GHWorkflowRun r : list) { | ||
if (r.getStatus().equals(GHWorkflowRun.Status.IN_PROGRESS) || r.getStatus().equals(GHWorkflowRun.Status.QUEUED)) { | ||
for (GHWorkflowJob j : r.listJobs()) { | ||
String label = !j.getLabels().isEmpty() ? j.getLabels().get(0) : null; | ||
if (label != null) { | ||
if (!queued.containsKey(label)) { | ||
queued.put(label, 0); | ||
} | ||
if (!running.containsKey(label)) { | ||
running.put(label, 0); | ||
} | ||
} | ||
|
||
if (j.getStatus().equals(GHWorkflowRun.Status.QUEUED)) { | ||
queued.put(label, queued.get(label) + 1); | ||
} else if (j.getStatus().equals(GHWorkflowRun.Status.IN_PROGRESS)) { | ||
running.put(label, running.get(label) + 1); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Set<String> runners = new HashSet<>(); | ||
runners.addAll(queued.keySet()); | ||
runners.addAll(running.keySet()); | ||
|
||
System.out.format("%-30s %-10s %-10s\n", "Runner", "Running", "Queued"); | ||
for (String r : runners) { | ||
System.out.format("%-30s %-10s %-10s\n", r, running.get(r), queued.get(r)); | ||
} | ||
System.out.println(); | ||
|
||
try { | ||
Thread.sleep(TimeUnit.MINUTES.toMillis(5)); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.github.stianst.gh; | ||
|
||
import io.github.stianst.gh.utils.Client; | ||
import org.kohsuke.github.GHOrganization; | ||
import org.kohsuke.github.GHTeam; | ||
import org.kohsuke.github.GHUser; | ||
import org.kohsuke.github.GitHub; | ||
|
||
import javax.json.JsonObject; | ||
import javax.json.JsonValue; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.PrintWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Hashtable; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
|
||
public class Teams { | ||
|
||
public static void main(String[] args) throws Exception { | ||
File file = new File("teams.txt"); | ||
if (file.isFile()) { | ||
file.delete(); | ||
} | ||
PrintWriter pw = new PrintWriter(new FileWriter(file)); | ||
|
||
GitHub gitHub = Client.getInstance().gitHub(); | ||
|
||
GHOrganization organization = gitHub.getOrganization("keycloak"); | ||
|
||
LinkedHashMap<String, List<String>> users = new LinkedHashMap<>(); | ||
|
||
for (GHUser user : organization.listMembers().toList()) { | ||
users.put(user.getLogin(), new LinkedList<>()); | ||
} | ||
|
||
Map<String, GHTeam> teams = organization.getTeams(); | ||
for (GHTeam team : teams.values()) { | ||
for (GHUser u : team.getMembers()) { | ||
users.get(u.getLogin()).add(team.getName()); | ||
} | ||
} | ||
|
||
for (String user : users.keySet().stream().sorted().toList()) { | ||
pw.println(user + "\t" + users.get(user).stream().sorted().collect(Collectors.joining(", "))); | ||
} | ||
|
||
System.out.println(file.getAbsolutePath()); | ||
|
||
pw.flush(); | ||
pw.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.github.stianst.gh; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class TeamsCheck { | ||
|
||
static Map<String, List<String>> users = loadUsers(); | ||
static Set<String> googleUsers = loadGoogleUsers(); | ||
|
||
public static void main(String[] args) { | ||
|
||
System.out.println("Not in google:"); | ||
users.keySet().stream().filter(u -> !googleUsers.contains(u)).forEach(TeamsCheck::printUser); | ||
|
||
System.out.println(); | ||
|
||
System.out.println("Not in github:"); | ||
googleUsers.stream().filter(u -> !users.containsKey(u)).forEach(TeamsCheck::printUser); | ||
} | ||
|
||
private static Map<String, List<String>> loadUsers() { | ||
try { | ||
File teamsFile = new File("teams.txt"); | ||
BufferedReader br = new BufferedReader(new FileReader(teamsFile)); | ||
Map<String, List<String>> users = new HashMap<>(); | ||
for (String l = br.readLine(); l != null; l = br.readLine()) { | ||
String[] split = l.split("\t"); | ||
users.put(split[0], Arrays.stream(split[1].split(", ")).toList()); | ||
} | ||
return users; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static Set<String> loadGoogleUsers() { | ||
try { | ||
File googleTeamsFile = new File("google-teams.txt"); | ||
|
||
Set<String> users = new HashSet<>(); | ||
BufferedReader br = new BufferedReader(new FileReader(googleTeamsFile)); | ||
for (String l = br.readLine(); l != null; l = br.readLine()) { | ||
users.add(l); | ||
} | ||
return users; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static void printUser(String user) { | ||
List<String> teams = users.get(user); | ||
if (teams != null && !teams.isEmpty()) { | ||
System.out.println(" - " + user + ": " + teams.stream().sorted().collect(Collectors.joining(", "))); | ||
} else { | ||
System.out.println(" - " + user + ": NO-TEAM"); | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
gh/src/main/java/io/github/stianst/gh/WorkflowRunTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.stianst.gh; | ||
|
||
import io.github.stianst.gh.rep.GHWorkflowRun; | ||
import io.github.stianst.gh.rep.GHWorkflowRuns; | ||
import io.github.stianst.gh.utils.GHCli; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class WorkflowRunTime { | ||
|
||
public static void main(String[] args) throws IOException, InterruptedException { | ||
GHCli ghCli = new GHCli(); | ||
|
||
String status = "success"; | ||
String branch = "main"; | ||
String created = "18-09-2024"; | ||
|
||
|
||
// List<GHWorkflowRuns> ghWorkflowRuns = ghCli.apiGet(GHWorkflowRuns.class, "repos/keycloak/keycloak/actions/workflows/ci.yml/runs", "--paginate", "-f", "status=" + status, "-f", "branch=" + branch, "-f", "created=" + created); | ||
List<GHWorkflowRuns> ghWorkflowRuns = ghCli.apiGet(GHWorkflowRuns.class, "repos/keycloak/keycloak/actions/workflows/ci.yml/runs", "--paginate", "-f", "created=>=2024-09-01", "-f", "event=workflow_dispatch"); | ||
|
||
List<GHWorkflowRun> list = ghWorkflowRuns.stream().flatMap(r -> r.workflowRuns().stream()).toList(); | ||
System.out.println(list.size()); | ||
|
||
for (GHWorkflowRun r : list) { | ||
long time = TimeUnit.MINUTES.convert(r.updatedAt().getTime() - r.createdAt().getTime(), TimeUnit.MILLISECONDS); | ||
System.out.println(r.id() + " " + time); | ||
} | ||
|
||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
gh/src/main/java/io/github/stianst/gh/rep/GHWorkflowRun.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.stianst.gh.rep; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Date; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record GHWorkflowRun( | ||
Long id, | ||
String name, | ||
String status, | ||
String conclusion, | ||
@JsonProperty("head_branch") | ||
String headBranch, | ||
@JsonProperty("created_at") | ||
Date createdAt, | ||
@JsonProperty("updated_at") | ||
Date updatedAt, | ||
String event, | ||
@JsonProperty("run_attempt") | ||
int runAttempt, | ||
String path) { | ||
} |
13 changes: 13 additions & 0 deletions
13
gh/src/main/java/io/github/stianst/gh/rep/GHWorkflowRuns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.stianst.gh.rep; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record GHWorkflowRuns( | ||
@JsonProperty("workflow_runs") | ||
List<GHWorkflowRun> workflowRuns) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.github.stianst.gh.utils; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class GHCli { | ||
|
||
private final JsonFactory jsonFactory = new JsonFactory(); | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public <T> List<T> apiGet(Class<T> clazz, String endpoint, String... args) throws IOException, InterruptedException { | ||
List<String> cmdarray = new LinkedList<>(); | ||
cmdarray.add("gh"); | ||
cmdarray.add("api"); | ||
cmdarray.add("-X"); | ||
cmdarray.add("GET"); | ||
cmdarray.add("--cache"); | ||
cmdarray.add("1h"); | ||
cmdarray.add(endpoint.startsWith("repos/") ? endpoint : ("repos/keycloak/keycloak/" + endpoint)); | ||
cmdarray.addAll(Arrays.asList(args)); | ||
|
||
File output = new File("ghcli-out.log"); | ||
|
||
ProcessBuilder pb = new ProcessBuilder(cmdarray); | ||
pb.environment().put("GH_DEBUG", "1"); | ||
pb.redirectError(new File("ghcli-err.log")); | ||
pb.redirectOutput(output); | ||
|
||
// System.out.println(String.join(" ", cmdarray)); | ||
|
||
Process process = pb.start(); | ||
if (!process.waitFor(30, TimeUnit.SECONDS)) { | ||
throw new IOException("Timed out, see ghcli-err.log for details"); | ||
} | ||
|
||
if (process.exitValue() != 0) { | ||
throw new IOException("Returned with " + process.exitValue() + ", see ghcli-err.log for details"); | ||
} | ||
|
||
// gh api --paginate returns multiple json documents | ||
JsonParser parser = jsonFactory.createParser(output); | ||
parser.setCodec(objectMapper); | ||
parser.nextToken(); | ||
List<T> list = new LinkedList<>(); | ||
while (parser.hasCurrentToken()) { | ||
list.add(parser.readValueAs(clazz)); | ||
parser.nextToken(); | ||
} | ||
return list; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Test { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Host: localhost:8080[\\r][\\n]".replace("[\\r]", "").replace("[\\n]", "")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
curl -X POST http://localhost:8080/realms/master/protocol/openid-connect/token -H "Content-Tyoe: application/json" \ | ||
-d "grant_type=client_credentials" \ | ||
-d "client_assertion_type=spiffe-jwt-svid" \ | ||
-d "client_assertion=$1" |
Oops, something went wrong.