Skip to content

Commit

Permalink
Allow to choose the branch name for repochecker
Browse files Browse the repository at this point in the history
Closes #74
  • Loading branch information
UncleSamSwiss committed Jan 17, 2025
1 parent 8bf56b1 commit 6a96909
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
11 changes: 11 additions & 0 deletions express/frontend/src/lib/gitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ export class GitHubRepoComm {
return result.data;
}

public readonly getBranches = AsyncCache.of(async () => {
const result = await this.request(
"GET /repos/{owner}/{repo}/branches",
{
...this.baseOptions,
per_page: 100,
},
);
return result.data;
});

public readonly getTags = AsyncCache.of(async () => {
const result = await this.request("GET /repos/{owner}/{repo}/tags", {
...this.baseOptions,
Expand Down
11 changes: 7 additions & 4 deletions express/frontend/src/lib/ioBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,12 @@ export interface CheckResults {
errors: CheckResult[];
}

export async function checkAdapter(repoName: string) {
const { data } = await axios.get<CheckResults>(
`${getApiUrl("repochecker/")}?url=${uc(`https://github.com/${repoName}`)}`,
);
export async function checkAdapter(repoName: string, branchName?: string) {
const url = new URL(getApiUrl("repochecker/"), window.location.origin);
url.searchParams.set("url", `https://github.com/${repoName}`);
if (branchName) {
url.searchParams.set("branch", branchName);
}
const { data } = await axios.get<CheckResults>(url.toString());
return data;
}
50 changes: 49 additions & 1 deletion express/frontend/src/tools/AdapterCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useEffect, useState } from "react";
import Chart from "react-google-charts";
import { useSearchParams } from "react-router-dom";
import { useUserToken } from "../contexts/UserContext";
import { GitHubComm } from "../lib/gitHub";
import { checkAdapter, CheckResult, getMyAdapterRepos } from "../lib/ioBroker";

export const iconStyles = {
Expand Down Expand Up @@ -95,6 +96,8 @@ export function AdapterCheck() {
const [searchParams] = useSearchParams();
const [repoNames, setRepoNames] = useState<string[]>([]);
const [repoName, setRepoName] = useState("");
const [branchNames, setBranchNames] = useState<string[]>([]);
const [branchName, setBranchName] = useState("");
const [busy, setBusy] = useState(false);
const [messages, setMessages] = useState<Message[]>([]);
useEffect(() => {
Expand All @@ -112,11 +115,38 @@ export function AdapterCheck() {
}
}, [repo]);

useEffect(() => {
setBranchName("");
setBranchNames([]);
let cancelled = false;
const loadBranches = async () => {
const [owner, repo] = repoName.split("/");
if (!owner || !repo) {
return;
}

const gitHub = GitHubComm.forToken(token);
const branches = await gitHub.getRepo(owner, repo).getBranches();
if (!cancelled) {
setBranchNames(
branches
.map((b) => b.name)
.filter((b) => !b.startsWith("dependabot/")),
);
}
};
loadBranches().catch(console.error);

return () => {
cancelled = true;
};
}, [repoName, token]);

const handleStartClick = async () => {
setMessages([]);
setBusy(true);
try {
const results = await checkAdapter(repoName);
const results = await checkAdapter(repoName, branchName);
const messages = results.errors.map((c) => new Message("error", c));
messages.push(
...results.warnings.map((c) => new Message("warning", c)),
Expand Down Expand Up @@ -176,6 +206,24 @@ export function AdapterCheck() {
)}
/>
</Grid2>
<Grid2>
<Autocomplete
freeSolo
disabled={busy || !repoName}
options={branchNames}
getOptionLabel={(option) => option}
sx={{ width: 170 }}
inputValue={branchName}
onInputChange={(_e, value) => setBranchName(value)}
renderInput={(params) => (
<TextField
{...params}
label="Branch (optional)"
variant="outlined"
/>
)}
/>
</Grid2>
<Grid2>
<Button
variant="contained"
Expand Down

0 comments on commit 6a96909

Please sign in to comment.