---
title: "Issues and pull requests"
description: "Read, create, review and merge issues and pull requests."
canonical_url: "https://forges.link/reference/threads"
---
# Issues and pull requests

> Read, create, review and merge issues and pull requests.

Issues, pull requests and the other discussion kinds are threads. For an operation that the forge lacks, see [Unsupported operations](https://forges.link/reference/provider#unsupported-operations).

## `provider.threads`

Issues, pull requests and the other kinds of discussion: reading, creating, commenting, labelling,
reviewing and merging them.

### `get()`

Reads an issue, pull request or discussion by its ref. Rejects with `NotFoundError` when it does not exist or the
credential cannot see it.

**Capability:** `threads.get`. Support differs by thread kind.

```ts
get(ref: ThreadRef, options?: BaseOptions): Promise<Thread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Thread>`](https://forges.link/reference/data-model#thread)

<api-explorer verb="threads.get">



</api-explorer>

### `getMany()`

Reads several threads, batched where the forge allows. Failures become per-item warnings, except a rate limit
(`RateLimitedError`) or a rejected credential (`TokenRevokedError`), which reject the call.

**Capability:** `threads.getMany`.

```ts
getMany(refs: ThreadRef[], options?: BaseOptions): Promise<GetManyResult[]>
```

| Parameter | Type |
| --- | --- |
| `refs` | [`ThreadRef[]`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<GetManyResult[]>`](https://forges.link/reference/data-model#getmanyresult)

<api-explorer verb="threads.getMany">



</api-explorer>

### `list()`

Lists the threads of a repository.

**Capability:** `threads.list`. Support differs by thread kind.

```ts
list(repo: RepoRef, query?: ThreadQuery): ForgeListing<Thread>
```

| Parameter | Type |
| --- | --- |
| `repo` | [`RepoRef`](https://forges.link/reference/data-model#reporef) |
| `query?` | [`ThreadQuery`](https://forges.link/reference/data-model#threadquery) |

**Returns:** `ForgeListing<Thread>`

<api-explorer verb="threads.list">



</api-explorer>

### `closingIssues()`

Lists the issues that a pull request closes when it merges, such as those its description names after `Fixes`.
They can be in other repositories. GitHub also lists the issues linked to the pull request by hand.

**Example**

```ts
for await (const issue of provider.threads.closingIssues(pull)) {
  console.log(`#${issue.ref.number} ${issue.title}`)
}
```

**Capability:** `threads.closingIssues`.

```ts
closingIssues(ref: ThreadRef, options?: PageOptions): ForgeListing<Thread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`PageOptions`](https://forges.link/reference/requests#pageoptions) |

**Returns:** `ForgeListing<Thread>`

<api-explorer verb="threads.closingIssues">



</api-explorer>

### `closingPullRequests()`

Lists the pull requests that close an issue when they merge, whether they are open, closed or merged.

**Capability:** `threads.closingPullRequests`.

```ts
closingPullRequests(ref: ThreadRef, options?: PageOptions): ForgeListing<Thread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`PageOptions`](https://forges.link/reference/requests#pageoptions) |

**Returns:** `ForgeListing<Thread>`

<api-explorer verb="threads.closingPullRequests">



</api-explorer>

### `events()`

Lists the events on a thread, such as comments, label changes and state changes.

**Capability:** `threads.events`.

```ts
events(ref: ThreadRef, options?: ListOptions): ForgeListing<ForgeEvent>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`ListOptions`](https://forges.link/reference/requests#listoptions) |

**Returns:** `ForgeListing<ForgeEvent>`

<api-explorer verb="threads.events">



</api-explorer>

### `comments()`

Conversation comments. Inline review comments are events, not comments.

**Capability:** `threads.comments`. Support differs by thread kind.

```ts
comments(ref: ThreadRef, options?: ListOptions): ForgeListing<Comment>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`ListOptions`](https://forges.link/reference/requests#listoptions) |

**Returns:** `ForgeListing<Comment>`

<api-explorer verb="threads.comments">



</api-explorer>

### `getComment()`

Reads one conversation comment, as `comments()` lists them, so not an inline review comment. Where the forge has
no endpoint for it (`capabilities.threads.getComment` is `'emulated'`), it lists the comments of the thread page by page
until the id matches, which costs a request for each page read.

**Capability:** `threads.getComment`. Support differs by thread kind.

```ts
getComment(ref: CommentRef, options?: BaseOptions): Promise<Comment>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`CommentRef`](https://forges.link/reference/data-model#commentref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Comment>`](https://forges.link/reference/data-model#comment)

### `createComment()`

Adds a comment to a thread. A repeat posts a second comment; to make it safe to retry, mark the body with
`withCommentMarker()` and retry with `upsertComment()`, both from `forges/helpers`.

**Example**

```ts
await provider.threads.createComment(ref, 'Deployed to staging')
```

**Capability:** `threads.createComment`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
createComment(ref: ThreadRef, body: string, options?: BaseOptions): Promise<Comment>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `body` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Comment>`](https://forges.link/reference/data-model#comment)

<api-explorer verb="threads.createComment">



</api-explorer>

### `updateComment()`

Replaces the body of a comment.

**Capability:** `threads.updateComment`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
updateComment(ref: CommentRef, body: string, options?: BaseOptions): Promise<Comment>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`CommentRef`](https://forges.link/reference/data-model#commentref) |
| `body` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Comment>`](https://forges.link/reference/data-model#comment)

<api-explorer verb="threads.updateComment">



</api-explorer>

### `deleteComment()`

Deletes a comment. A repeat can reject with `NotFoundError` once the comment is gone.

**Capability:** `threads.deleteComment`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
deleteComment(ref: CommentRef, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`CommentRef`](https://forges.link/reference/data-model#commentref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.deleteComment">



</api-explorer>

### `hideComment()`

Hides a comment behind a note of the reason, as GitHub does when it minimises a comment. A repeat leaves it hidden.

**Example**

```ts
await provider.threads.hideComment(comment.ref, 'spam')
```

**Capability:** `threads.hideComment`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
hideComment(ref: CommentRef, reason: HideCommentReason, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`CommentRef`](https://forges.link/reference/data-model#commentref) |
| `reason` | [`HideCommentReason`](https://forges.link/reference/data-model#hidecommentreason) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.hideComment">



</api-explorer>

### `unhideComment()`

Shows a hidden comment again. A repeat leaves it shown.

**Capability:** `threads.hideComment`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
unhideComment(ref: CommentRef, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`CommentRef`](https://forges.link/reference/data-model#commentref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.unhideComment">



</api-explorer>

### `create()`

Creates an issue, pull request or discussion. A pull request needs `head` and `base`. A repeat creates a second
thread, though most forges reject a second open pull request from the same `head` to the same `base`.

**Capability:** `threads.create`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
create(repo: RepoRef, input: ThreadInput, options?: BaseOptions): Promise<Thread>
```

| Parameter | Type |
| --- | --- |
| `repo` | [`RepoRef`](https://forges.link/reference/data-model#reporef) |
| `input` | [`ThreadInput`](https://forges.link/reference/data-model#threadinput) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Thread>`](https://forges.link/reference/data-model#thread)

<api-explorer verb="threads.create">



</api-explorer>

### `update()`

Changes the title, body, state, labels or assignees of a thread. Fields left out stay as they are.
This is one request where the forge accepts every field together. Elsewhere it makes the same calls as
`close()`, `setLabels()` and `setAssignees()`, so a failed call can leave earlier fields changed.
A field the forge cannot set on this kind of thread throws `UnsupportedOperationError` before anything is written.

**Example**

```ts
await provider.threads.update(ref, { state: 'closed', labels: ['wontfix'], assignees: [] })
```

**Capability:** `threads.update`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
update(ref: ThreadRef, input: ThreadUpdate, options?: BaseOptions): Promise<Thread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `input` | [`ThreadUpdate`](https://forges.link/reference/data-model#threadupdate) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Thread>`](https://forges.link/reference/data-model#thread)

<api-explorer verb="threads.update">



</api-explorer>

### `setLabels()`

Replaces the thread's labels.

**Capability:** `threads.setLabels`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
setLabels(ref: ThreadRef, labels: string[], options?: BaseOptions): Promise<Label[]>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `labels` | `string[]` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Label[]>`](https://forges.link/reference/data-model#label) The labels the thread carries afterwards. GitLab and Azure DevOps report only their names.

<api-explorer verb="threads.setLabels">



</api-explorer>

### `addLabels()`

Adds labels, leaving the rest in place.

**Capability:** `threads.addLabels`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
addLabels(ref: ThreadRef, labels: string[], options?: BaseOptions): Promise<Label[]>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `labels` | `string[]` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Label[]>`](https://forges.link/reference/data-model#label) The labels the thread carries afterwards. GitLab reports only their names.

<api-explorer verb="threads.addLabels">



</api-explorer>

### `removeLabels()`

Removes labels, leaving the rest in place. Labels the thread does not carry are ignored.

**Capability:** `threads.removeLabels`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
removeLabels(ref: ThreadRef, labels: string[], options?: BaseOptions): Promise<Label[]>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `labels` | `string[]` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Label[]>`](https://forges.link/reference/data-model#label) The labels the thread carries afterwards. GitLab reports only their names. Forgejo, Gitea and Gitee read the labels after removing them, and GitHub reads them when it removes none.

<api-explorer verb="threads.removeLabels">



</api-explorer>

### `setMilestone()`

Sets the thread's milestone, by milestone, id or title, or clears it with `undefined`.

**Capability:** `threads.setMilestone`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
setMilestone(ref: ThreadRef, milestone: Milestone | string | undefined, options?: BaseOptions): Promise<Milestone | undefined>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `milestone` | [`Milestone \| string \| undefined`](https://forges.link/reference/data-model#milestone) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Milestone | undefined>`](https://forges.link/reference/data-model#milestone) The milestone the thread is in afterwards, or `undefined` once it is cleared.

<api-explorer verb="threads.setMilestone">



</api-explorer>

### `setIssueType()`

Sets the issue's type, by issue type or name, or clears it with `undefined`. GitHub leaves the type as it was,
without an error, when the account cannot push to the repository, so compare the result with what you asked for.

**Example**

```ts
const bug = (await provider.repos.issueTypes(repo)).find(type => type.name === 'Bug')
await provider.threads.setIssueType(ref, bug)
```

**Capability:** `threads.setIssueType`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
setIssueType(ref: ThreadRef, issueType: IssueType | string | undefined, options?: BaseOptions): Promise<IssueType | undefined>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `issueType` | [`IssueType \| string \| undefined`](https://forges.link/reference/data-model#issuetype) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<IssueType | undefined>`](https://forges.link/reference/data-model#issuetype) The type the issue has afterwards, or `undefined` once it is cleared.

<api-explorer verb="threads.setIssueType">



</api-explorer>

### `reactions()`

Reactions left on the thread or on one of its comments.

**Capability:** `threads.reactions`. Support differs by thread kind.

```ts
reactions(target: ThreadRef | CommentRef, options?: ListOptions): ForgeListing<Reaction>
```

| Parameter | Type |
| --- | --- |
| `target` | `ThreadRef \| CommentRef` |
| `options?` | [`ListOptions`](https://forges.link/reference/requests#listoptions) |

**Returns:** `ForgeListing<Reaction>`

<api-explorer verb="threads.reactions">



</api-explorer>

### `react()`

Reacts as the authenticated account, to the thread or to one of its comments.

**Capability:** `threads.react`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
react(target: ThreadRef | CommentRef, reaction: ReactionContent, options?: BaseOptions): Promise<void>
```

| Parameter | Type | Description |
| --- | --- | --- |
| `target` | `ThreadRef \| CommentRef` | The thread or comment to react to. |
| `reaction` | [`ReactionContent`](https://forges.link/reference/data-model#reactioncontent) | The reaction to leave. |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |  |

**Returns:** `Promise<void>`

<api-explorer verb="threads.react">



</api-explorer>

### `unreact()`

Removes the account's reaction from the thread or comment.

**Capability:** `threads.react`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
unreact(target: ThreadRef | CommentRef, reaction: ReactionContent, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `target` | `ThreadRef \| CommentRef` |
| `reaction` | [`ReactionContent`](https://forges.link/reference/data-model#reactioncontent) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.unreact">



</api-explorer>

### `transfer()`

Moves the thread to another repository, and returns its ref there. A repeat can reject once the thread has moved.

**Capability:** `threads.transfer`. Read-only and anonymous providers reject it.

```ts
transfer(ref: ThreadRef, repo: RepoRef, options?: BaseOptions): Promise<ResolvedThreadRef>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `repo` | [`RepoRef`](https://forges.link/reference/data-model#reporef) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<ResolvedThreadRef>`](https://forges.link/reference/data-model#resolvedthreadref)

<api-explorer verb="threads.transfer">



</api-explorer>

### `markDuplicate()`

Marks the thread a duplicate of `canonical`, which must be in the same repository on most forges.

**Capability:** `threads.markDuplicate`. Read-only and anonymous providers reject it.

```ts
markDuplicate(ref: ThreadRef, canonical: ThreadRef, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `canonical` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.markDuplicate">



</api-explorer>

### `setAssignees()`

Replaces the thread's assignees.

**Capability:** `threads.setAssignees`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
setAssignees(ref: ThreadRef, assignees: Array<string | Actor>, options?: BaseOptions): Promise<Actor[]>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `assignees` | [`Array<string \| Actor>`](https://forges.link/reference/data-model#actor) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Actor[]>`](https://forges.link/reference/data-model#actor) The accounts assigned afterwards.

<api-explorer verb="threads.setAssignees">



</api-explorer>

### `requestReview()`

Adds reviewers to a pull request.

**Capability:** `threads.requestReview`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
requestReview(ref: ThreadRef, reviewers: Array<string | Actor>, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `reviewers` | [`Array<string \| Actor>`](https://forges.link/reference/data-model#actor) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.requestReview">



</api-explorer>

### `close()`

Closes a thread, optionally with a reason.

**Capability:** `threads.close`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
close(ref: ThreadRef, options?: CloseOptions): Promise<Thread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`CloseOptions`](https://forges.link/reference/data-model#closeoptions) |

**Returns:** [`Promise<Thread>`](https://forges.link/reference/data-model#thread) The thread, closed. Tangled reads the thread after writing the state record.

<api-explorer verb="threads.close">



</api-explorer>

### `reopen()`

Reopens a closed thread.

**Capability:** `threads.reopen`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
reopen(ref: ThreadRef, options?: BaseOptions): Promise<Thread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Thread>`](https://forges.link/reference/data-model#thread) The thread, open. Tangled reads the thread after writing the state record.

<api-explorer verb="threads.reopen">



</api-explorer>

### `lock()`

Locks the conversation on a thread, so that only collaborators can comment. A repeat leaves it locked.

**Example**

```ts
await provider.threads.lock(ref, { reason: 'too_heated' })
```

**Capability:** `threads.lock`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
lock(ref: ThreadRef, options?: LockOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`LockOptions`](https://forges.link/reference/data-model#lockoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.lock">



</api-explorer>

### `unlock()`

Unlocks the conversation on a thread. A repeat leaves it unlocked.

**Capability:** `threads.lock`. Support differs by thread kind. Read-only and anonymous providers reject it.

```ts
unlock(ref: ThreadRef, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.unlock">



</api-explorer>

### `merge()`

Merges a pull request. Without a merge method, the repository must allow exactly one. A repeat rejects once the
pull request has merged, so after a failure read the pull request to see whether it did.

**Example**

```ts
const { status, sha } = await provider.threads.merge(ref, { method: 'squash' })
```

**Capability:** `threads.merge`. Read-only and anonymous providers reject it.

```ts
merge(ref: ThreadRef, options?: MergeOptions): Promise<MergeResult>
```

| Parameter | Type | Description |
| --- | --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) | The pull request to merge. |
| `options?` | [`MergeOptions`](https://forges.link/reference/data-model#mergeoptions) | The merge method, the head `sha` to expect and the commit message. |

**Returns:** [`Promise<MergeResult>`](https://forges.link/reference/data-model#mergeresult) Whether the pull request merged or the forge queued the merge, and the merge commit where the response
reports it. Forgejo, Gitea and Tangled report no merge commit.

<api-explorer verb="threads.merge">



</api-explorer>

### `updateBranch()`

Brings the base branch into a pull request's head branch, by a merge commit or a rebase. A repeat once the branch
is up to date rejects on GitHub, Forgejo and Gitea, and leaves the branch as it is on GitLab.

**Example**

```ts
await provider.threads.updateBranch(ref, { method: 'rebase', sha: pull.branches?.head.sha })
```

**Capability:** `threads.updateBranch`. Read-only and anonymous providers reject it.

```ts
updateBranch(ref: ThreadRef, options?: UpdateBranchOptions): Promise<UpdateBranchResult>
```

| Parameter | Type | Description |
| --- | --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) | The pull request to update. |
| `options?` | [`UpdateBranchOptions`](https://forges.link/reference/data-model#updatebranchoptions) | The update `method`, and the head `sha` to expect. GitHub checks `sha` as it updates; Forgejo, Gitea and GitLab read the pull request first and compare. |

**Returns:** [`Promise<UpdateBranchResult>`](https://forges.link/reference/data-model#updatebranchresult) Whether the branch was updated or the forge queued the update. GitHub and GitLab update in the background,
so read the pull request later to see the new head.

<api-explorer verb="threads.updateBranch">



</api-explorer>

### `subscription()`

The authenticated account's subscription to the thread.

**Capability:** `threads.subscription`. Support differs by thread kind. Anonymous providers reject it.

```ts
subscription(ref: ThreadRef, options?: BaseOptions): Promise<SubscriptionState>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<SubscriptionState>`](https://forges.link/reference/data-model#subscriptionstate)

<api-explorer verb="threads.subscription">



</api-explorer>

### `subscribe()`

Subscribes the account to the notifications of a thread.

**Capability:** `threads.subscribe`. Read-only and anonymous providers reject it.

```ts
subscribe(ref: ThreadRef, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.subscribe">



</api-explorer>

### `unsubscribe()`

Stops the account's notifications for a thread, leaving existing notifications alone.

**Capability:** `threads.subscribe`. Read-only and anonymous providers reject it.

```ts
unsubscribe(ref: ThreadRef, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.unsubscribe">



</api-explorer>

### `checks()`

Every check on the pull's head, in one page; `warnings` names the sources that could not be read.

**Capability:** `threads.checks`. Support differs by thread kind.

```ts
checks(ref: ThreadRef, options?: BaseOptions): Promise<Page<Check>>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Page<Check>>`](https://forges.link/reference/data-model#check)

<api-explorer verb="threads.checks">



</api-explorer>

### `reviews()`

Reviews on a pull request. Forges with approvals but no review objects
(GitLab approvals, Azure DevOps votes, Bitbucket participants) synthesise
one review per approver, with `comments: false`.

**Capability:** `threads.reviews`.

```ts
reviews(ref: ThreadRef, options?: PageOptions): ForgeListing<Review>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`PageOptions`](https://forges.link/reference/requests#pageoptions) |

**Returns:** `ForgeListing<Review>`

<api-explorer verb="threads.reviews">



</api-explorer>

### `getReview()`

Reads one review by its ref. Where the forge has no endpoint for it (`capabilities.threads.getReview` is `'emulated'`),
it lists the reviews of the pull request page by page until the id matches, which costs a request for each page
read.

**Capability:** `threads.getReview`.

```ts
getReview(ref: ReviewRef, options?: BaseOptions): Promise<Review>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ReviewRef`](https://forges.link/reference/data-model#reviewref) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Review>`](https://forges.link/reference/data-model#review)

### `createReview()`

Creates a review. Without `event` the review is pending where the forge has pending reviews. A repeat adds a second review.

**Capability:** `threads.createReview`. Read-only and anonymous providers reject it.

```ts
createReview(ref: ThreadRef, input: ReviewInput, options?: BaseOptions): Promise<Review>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `input` | [`ReviewInput`](https://forges.link/reference/data-model#reviewinput) |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Review>`](https://forges.link/reference/data-model#review)

<api-explorer verb="threads.createReview">



</api-explorer>

### `submitReview()`

Submits a pending review. A repeat can reject once the review is submitted.

**Capability:** `threads.submitReview`. Read-only and anonymous providers reject it.

```ts
submitReview(ref: ReviewRef, event: ReviewEvent, body?: string, options?: BaseOptions): Promise<Review>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ReviewRef`](https://forges.link/reference/data-model#reviewref) |
| `event` | [`ReviewEvent`](https://forges.link/reference/data-model#reviewevent) |
| `body?` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Review>`](https://forges.link/reference/data-model#review)

<api-explorer verb="threads.submitReview">



</api-explorer>

### `approve()`

Approves without merging; `createReview({ event: 'approve' })` with nothing else to say. A repeat adds a second
approving review where the forge keeps reviews, and sets the same vote or rejects where it keeps votes.

**Capability:** `threads.approve`. Read-only and anonymous providers reject it.

```ts
approve(ref: ThreadRef, body?: string, options?: BaseOptions): Promise<Review>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `body?` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<Review>`](https://forges.link/reference/data-model#review) The approval, as `createReview()` returns it. GitLab reads the signed-in account once per provider to
pick the approval out of a response with more than one approver.

<api-explorer verb="threads.approve">



</api-explorer>

### `files()`

Files a pull request changes, with a per-file `patch` where the forge returns one.

**Capability:** `threads.files`.

```ts
files(ref: ThreadRef, options?: PageOptions): ForgeListing<ChangedFile>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`PageOptions`](https://forges.link/reference/requests#pageoptions) |

**Returns:** `ForgeListing<ChangedFile>`

<api-explorer verb="threads.files">



</api-explorer>

### `commits()`

Commits on a pull request.

**Capability:** `threads.commits`.

```ts
commits(ref: ThreadRef, options?: PageOptions): ForgeListing<Commit>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`PageOptions`](https://forges.link/reference/requests#pageoptions) |

**Returns:** `ForgeListing<Commit>`

<api-explorer verb="threads.commits">



</api-explorer>

### `replyToReviewComment()`

Replies to a review comment in its conversation. Pass the comment as `reviews()` or `comments()` returns it:
GitHub uses its `inReplyTo` or `ref`, Gitea its `ref`, and GitLab the discussion in its `thread`. A repeat posts a
second reply.

**Capability:** `threads.replyToReviewComment`. Read-only and anonymous providers reject it.

```ts
replyToReviewComment(ref: ThreadRef, comment: Pick<ReviewComment, 'ref' | 'thread' | 'inReplyTo'>, body: string, options?: BaseOptions): Promise<ReviewComment>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `comment` | [`Pick<ReviewComment, 'ref' \| 'thread' \| 'inReplyTo'>`](https://forges.link/reference/data-model#reviewcomment) |
| `body` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** [`Promise<ReviewComment>`](https://forges.link/reference/data-model#reviewcomment)

<api-explorer verb="threads.replyToReviewComment">



</api-explorer>

### `reviewThreads()`

Review conversations on a pull request with their comments; `state` keeps only the resolved or the unresolved ones.

**Capability:** `threads.reviewThreads`.

```ts
reviewThreads(ref: ThreadRef, options?: ReviewThreadListOptions): ForgeListing<ReviewThread>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `options?` | [`ReviewThreadListOptions`](https://forges.link/reference/data-model#reviewthreadlistoptions) |

**Returns:** `ForgeListing<ReviewThread>`

<api-explorer verb="threads.reviewThreads">



</api-explorer>

### `resolveReviewThread()`

Resolves a review conversation, by the id on `ReviewComment.thread` or `Comment.thread`.

**Capability:** `threads.resolveReviewThread`. Read-only and anonymous providers reject it.

```ts
resolveReviewThread(ref: ThreadRef, id: string, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `id` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.resolveReviewThread">



</api-explorer>

### `unresolveReviewThread()`

Reopens a resolved review conversation, by the id on `ReviewComment.thread` or `Comment.thread`.

**Capability:** `threads.resolveReviewThread`. Read-only and anonymous providers reject it.

```ts
unresolveReviewThread(ref: ThreadRef, id: string, options?: BaseOptions): Promise<void>
```

| Parameter | Type |
| --- | --- |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) |
| `id` | `string` |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |

**Returns:** `Promise<void>`

<api-explorer verb="threads.unresolveReviewThread">



</api-explorer>

## Comment helpers

Import from `forges/helpers`. They call the methods of `provider.threads`, so they work with any provider.

### `UpsertCommentInput`

What [`upsertComment`](https://forges.link/reference/threads#upsertcomment) needs.

| Member | Type | Description |
| --- | --- | --- |
| `key` | `string` | Identifies the comment to replace across runs. It is written into the body as an HTML comment, so it is invisible when rendered but matchable on the next run. |
| `body` | `string` |  |
| `since?` | `Date` | Only comments updated at or after this time are searched for the key. When retrying a change, pass the time of its first attempt, less a margin for clock skew, so the retry lists only recent comments. A comment with the same key from before `since` is not found, and a new one is created. |

### `UpsertCommentResult`

What [`upsertComment`](https://forges.link/reference/threads#upsertcomment) did.

**type parameters:** `T extends Comment | CommitComment = Comment`

| Member | Type | Description |
| --- | --- | --- |
| `comment` | `T` | The comment that was created or edited. |
| `created` | `boolean` | `false` when a comment with the same key already existed, and was edited or already had the body. |

### `commentMarker()`

The hidden marker that [`upsertComment`](https://forges.link/reference/threads#upsertcomment) writes into a comment body to
find it again. It renders as nothing on every forge that renders Markdown
as HTML.

```ts
function commentMarker(key: string): string
```

| Parameter | Type |
| --- | --- |
| `key` | `string` |

**Returns:** `string`

### `hasCommentMarker()`

Whether `body` carries the marker for `key`.

```ts
function hasCommentMarker(body: string, key: string): boolean
```

| Parameter | Type |
| --- | --- |
| `body` | `string` |
| `key` | `string` |

**Returns:** `boolean`

### `withCommentMarker()`

`body` with the marker for `key` at the end, unless it carries it already. Post it with `threads.createComment()` so that
[`upsertComment`](https://forges.link/reference/threads#upsertcomment) with the same key edits that comment instead of posting another.

**Example**

```ts
await provider.threads.createComment(ref, withCommentMarker('Deployed to staging', mutationId))
```

```ts
function withCommentMarker(body: string, key: string): string
```

| Parameter | Type |
| --- | --- |
| `body` | `string` |
| `key` | `string` |

**Returns:** `string`

### `upsertComment()`

Creates the comment, or edits the one an earlier call with the same `key` left behind, unless that one already has
the same body. The key is carried in the body as a hidden marker; see [`commentMarker`](https://forges.link/reference/threads#commentmarker). It lists the comments
of the thread on every call, which `since` bounds, so the provider needs `threads.comments()`, `threads.createComment()`
and `threads.updateComment()` for the kind of thread. On a commit it uses `commits.comments()`, `commits.createComment()`
and `commits.updateComment()`, and reads every comment of the commit.

**Example**

```ts
import { upsertComment } from 'forges/helpers'

await upsertComment(provider, ref, { key: 'preview', body: 'Preview: https://pr-42.example.com' })
```

**Overload 1 of 2**

```ts
function upsertComment(provider: ForgeProvider, ref: CommitRef, input: UpsertCommentInput, options?: BaseOptions): Promise<UpsertCommentResult<CommitComment>>
```

| Parameter | Type | Description |
| --- | --- | --- |
| `provider` | [`ForgeProvider`](https://forges.link/reference/provider) | The provider to comment with. |
| `ref` | [`CommitRef`](https://forges.link/reference/data-model#commitref) | The thread or commit to comment on. |
| `input` | [`UpsertCommentInput`](https://forges.link/reference/threads#upsertcommentinput) | The `key` that identifies the comment across runs, its `body`, and `since` to look at recent comments only. |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |  |

**Returns:** `Promise<UpsertCommentResult<CommitComment>>`

**Overload 2 of 2**

```ts
function upsertComment(provider: ForgeProvider, ref: ThreadRef, input: UpsertCommentInput, options?: BaseOptions): Promise<UpsertCommentResult>
```

| Parameter | Type | Description |
| --- | --- | --- |
| `provider` | [`ForgeProvider`](https://forges.link/reference/provider) | The provider to comment with. |
| `ref` | [`ThreadRef`](https://forges.link/reference/data-model#threadref) | The thread or commit to comment on. |
| `input` | [`UpsertCommentInput`](https://forges.link/reference/threads#upsertcommentinput) | The `key` that identifies the comment across runs, its `body`, and `since` to look at recent comments only. |
| `options?` | [`BaseOptions`](https://forges.link/reference/requests#baseoptions) |  |

**Returns:** [`Promise<UpsertCommentResult>`](https://forges.link/reference/threads#upsertcommentresult)


## Sitemap

See the full [sitemap](https://forges.link/sitemap.md) for all pages.
