Skip to content

Merge requests

Use client.MergeRequests to manage merge requests and their notes. The iid is the merge request number within a project (for example, 8), not its global Id.

List methods return the server's current page; they do not fetch every page automatically. Create, update, close, and note creation write to the selected project.

Setup

Replace the example token and project ID with your own. Python examples call each API from an async function, then run that function with asyncio.run. In an existing async application, call the API with await inside its running event loop. The repository runs these exact snippets against offline fixtures during documentation checks.

#r "nuget: DataHubClient"

open DataHubClient

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

const client = new DataHubClient("https://git.nfdi4plants.org", Authentication.PersonalAccessToken("your-datahub-pat"));
const projectId = 42;
import asyncio
from datahub_client import DataHubClient, Authentication

client = DataHubClient("https://git.nfdi4plants.org", Authentication.PersonalAccessToken("your-datahub-pat"))
project_id = 42

ListAsync

List merge requests, optionally filtered by state. Omit state to use the server default.

let mergeRequests = client.MergeRequests.ListAsync(projectId, state = "opened") |> Async.RunSynchronously
for item in mergeRequests do printfn $"{item.Iid}: {item.Title}"
const mergeRequests = await client.MergeRequests.ListAsync(projectId, "opened");
for (const item of mergeRequests) console.log(`${item.Iid}: ${item.Title}`);
async def list_example():
    return await client.MergeRequests.ListAsync(project_id, state="opened")


merge_requests = asyncio.run(list_example())
for item in merge_requests:
    print(f"{item.Iid}: {item.Title}")

GetAsync

Read one merge request by its project-local number.

let mergeRequest = client.MergeRequests.GetAsync(projectId, 8) |> Async.RunSynchronously
printfn "%s" mergeRequest.Title
const mergeRequest = await client.MergeRequests.GetAsync(projectId, 8);
console.log(mergeRequest.Title);
async def get_example():
    return await client.MergeRequests.GetAsync(project_id, 8)


merge_request = asyncio.run(get_example())
print(merge_request.Title)

CreateAsync

Propose changes from a source branch into a target branch. Both branches must already exist. The returned Iid identifies the merge request for subsequent calls.

let created =
    client.MergeRequests.CreateAsync(projectId, "feature/assay", "main", "Add assay metadata", description = "Describe the assay.")
    |> Async.RunSynchronously
printfn "%s" created.WebUrl
const created = await client.MergeRequests.CreateAsync(
  projectId, "feature/assay", "main", "Add assay metadata", "Describe the assay."
);
console.log(created.WebUrl);
async def create_example():
    return await client.MergeRequests.CreateAsync(
        project_id, "feature/assay", "main", "Add assay metadata", description="Describe the assay."
    )


created = asyncio.run(create_example())
print(created.WebUrl)

UpdateAsync

Change the title or description. Omitted fields remain unchanged. Use stateEvent = "reopen" (Python: state_event="reopen") to reopen a closed merge request; JavaScript and TypeScript take this as the fifth argument.

let updated =
    client.MergeRequests.UpdateAsync(projectId, 8, title = "Complete assay metadata", description = "Add protocol details.")
    |> Async.RunSynchronously
printfn "%s" updated.Title
const updated = await client.MergeRequests.UpdateAsync(
  projectId, 8, "Complete assay metadata", "Add protocol details."
);
console.log(updated.Title);
async def update_example():
    return await client.MergeRequests.UpdateAsync(
        project_id, 8, title="Complete assay metadata", description="Add protocol details."
    )


updated = asyncio.run(update_example())
print(updated.Title)

CloseAsync

Close a merge request and return its updated state. Closing a merge request does not merge its source branch.

let closed = client.MergeRequests.CloseAsync(projectId, 8) |> Async.RunSynchronously
printfn "%s" closed.State
const closed = await client.MergeRequests.CloseAsync(projectId, 8);
console.log(closed.State);
async def close_example():
    return await client.MergeRequests.CloseAsync(project_id, 8)


closed = asyncio.run(close_example())
print(closed.State)

NotesAsync

Read the notes on a merge request. System distinguishes automatically generated notes from user comments.

let notes = client.MergeRequests.NotesAsync(projectId, 8) |> Async.RunSynchronously
for note in notes do printfn "%s" note.Body
const notes = await client.MergeRequests.NotesAsync(projectId, 8);
for (const note of notes) console.log(note.Body);
async def notes_example():
    return await client.MergeRequests.NotesAsync(project_id, 8)


notes = asyncio.run(notes_example())
for note in notes:
    print(note.Body)

CreateNoteAsync

Add a Markdown comment and return the created note.

let note = client.MergeRequests.CreateNoteAsync(projectId, 8, "Metadata reviewed.") |> Async.RunSynchronously
printfn "%s" note.Body
const note = await client.MergeRequests.CreateNoteAsync(projectId, 8, "Metadata reviewed.");
console.log(note.Body);
async def create_note_example():
    return await client.MergeRequests.CreateNoteAsync(project_id, 8, "Metadata reviewed.")


note = asyncio.run(create_note_example())
print(note.Body)