Skip to content

Repository

Read branches and commits using a numeric project ID. List methods return one server page.

Setup

These snippets share this client. Replace the URL and token with your DataHub details. The complete sample files use offline responses when run by the documentation checks.

#r "nuget: DataHubClient"

open DataHubClient

let client =
    DataHubClient("https://hub.example", Authentication.PersonalAccessToken("your-datahub-pat"))
import { DataHubClient } from "@nfdi4plants/datahub-client";
import { Authentication } from "@nfdi4plants/datahub-client/Http/Authentication.js";

const client = new DataHubClient(
  "https://hub.example", Authentication.PersonalAccessToken("your-datahub-pat"));
import asyncio
from datahub_client import DataHubClient, Authentication

client = DataHubClient(
    "https://hub.example", Authentication.PersonalAccessToken("your-datahub-pat"))

ListBranchesAsync

List branches, optionally filtering their names with search.

let branches =
    client.Repository.ListBranchesAsync(42, search = "main") |> Async.RunSynchronously
for branch in branches do printfn "%s: %s" branch.Name branch.Commit.ShortId
const branches = await client.Repository.ListBranchesAsync(42, "main");
for (const branch of branches) console.log(branch.Name, branch.Commit.ShortId);
async def list_branches_example():
    branches = await client.Repository.ListBranchesAsync(42, search="main")
    for branch in branches:
        print(branch.Name, branch.Commit.ShortId)


asyncio.run(list_branches_example())

GetBranchAsync

Get a branch by its name.

let branch =
    client.Repository.GetBranchAsync(42, "main") |> Async.RunSynchronously
printfn "%s points to %s" branch.Name branch.Commit.Id
const branch = await client.Repository.GetBranchAsync(42, "main");
console.log(`${branch.Name} points to ${branch.Commit.Id}`);
async def get_branch_example():
    branch = await client.Repository.GetBranchAsync(42, "main")
    print(f"{branch.Name} points to {branch.Commit.Id}")


asyncio.run(get_branch_example())

ListCommitsAsync

List commits, optionally choosing a branch, tag, or SHA with refName (ref_name in Python), and restricting the history to path.

let commits =
    client.Repository.ListCommitsAsync(42, refName = "main", path = "README.md") |> Async.RunSynchronously
for commit in commits do printfn "%s: %s" commit.ShortId commit.Title
const commits = await client.Repository.ListCommitsAsync(42, "main", "README.md");
for (const commit of commits) console.log(commit.ShortId, commit.Title);
async def list_commits_example():
    commits = await client.Repository.ListCommitsAsync(42, ref_name="main", path="README.md")
    for commit in commits:
        print(commit.ShortId, commit.Title)


asyncio.run(list_commits_example())

GetCommitAsync

Read a single commit by SHA.

let commit =
    client.Repository.GetCommitAsync(42, "abc123def456") |> Async.RunSynchronously
printfn "%s by %s" commit.Title commit.AuthorName
const commit = await client.Repository.GetCommitAsync(42, "abc123def456");
console.log(`${commit.Title} by ${commit.AuthorName}`);
async def get_commit_example():
    commit = await client.Repository.GetCommitAsync(42, "abc123def456")
    print(f"{commit.Title} by {commit.AuthorName}")


asyncio.run(get_commit_example())