<commit_before>import {
  PullRequestDatabase,
  IPullRequest,
  IPullRequestStatus,
} from '../databases'
import { GitHubRepository } from '../../models/github-repository'
import { Account } from '../../models/account'
import { API, IAPIPullRequest } from '../api'
import { fatalError, forceUnwrap } from '../fatal-error'
import { RepositoriesStore } from './repositories-store'
import {
  PullRequest,
  PullRequestRef,
  PullRequestStatus,
} from '../../models/pull-request'

/** The store for GitHub Pull Requests. */
export class PullRequestStore {
  private readonly db: PullRequestDatabase
  private readonly repositoriesStore: RepositoriesStore

  public constructor(
    db: PullRequestDatabase,
    repositoriesStore: RepositoriesStore
  ) {
    this.db = db
    this.repositoriesStore = repositoriesStore
  }

  /** Update the list of open pull requests for the repository. */
  public async refreshPullRequests(
    repository: GitHubRepository,
    account: Account
  ): Promise<ReadonlyArray<PullRequest>> {
    const api = API.fromAccount(account)

    const prsFromAPI = await api.fetchPullRequests(
      repository.owner.login,
      repository.name,
      'open'
    )

    await this.writePullRequests(prsFromAPI, repository)

    return await this.getPullRequests(repository)
  }

  public async refreshPullRequestStatuses(
    pullRequests: Array<PullRequest>,
    repository: GitHubRepository,
    account: Account
  ): Promise<ReadonlyArray<IPullRequestStatus>> {
    const api = API.fromAccount(account)

    const pullRequestsStatuses: Array<IPullRequestStatus> = []

    for (const pr of pullRequests) {
      const status = await api.fetchCombinedRefStatus(
        repository.owner.login,
        repository.name,
        pr.head.sha
      )

      pullRequestsStatuses.push({
        state: status.state,
        totalCount: status.total_count,
        pullRequestId: pr.id,
        sha: pr.head.sha,
      })
    }

    await this.writePullRequestStatus(pullRequestsStatuses)

    return pullRequestsStatuses<commit_msg>Use function to write PR statuses<commit_after>import {
  PullRequestDatabase,
  IPullRequest,
  IPullRequestStatus,
} from '../databases'
import { GitHubRepository } from '../../models/github-repository'
import { Account } from '../../models/account'
import { API, IAPIPullRequest } from '../api'
import { fatalError, forceUnwrap } from '../fatal-error'
import { RepositoriesStore } from './repositories-store'
import {
  PullRequest,
  PullRequestRef,
  PullRequestStatus,
} from '../../models/pull-request'

/** The store for GitHub Pull Requests. */
export class PullRequestStore {
  private readonly db: PullRequestDatabase
  private readonly repositoriesStore: RepositoriesStore

  public constructor(
    db: PullRequestDatabase,
    repositoriesStore: RepositoriesStore
  ) {
    this.db = db
    this.repositoriesStore = repositoriesStore
  }

  /** Update the list of open pull requests for the repository. */
  public async refreshPullRequests(
    repository: GitHubRepository,
    account: Account
  ): Promise<ReadonlyArray<PullRequest>> {
    const api = API.fromAccount(account)

    const prsFromAPI = await api.fetchPullRequests(
      repository.owner.login,
      repository.name,
      'open'
    )

    await this.writePullRequests(prsFromAPI, repository)

    return await this.getPullRequests(repository)
  }

  public async refreshPullRequestStatuses(
    pullRequests: Array<PullRequest>,
    repository: GitHubRepository,
    account: Account
  ): Promise<ReadonlyArray<PullRequestStatus>> {
    const api = API.fromAccount(account)

    const pullRequestsStatuses: Array<IPullRequestStatus> = []

    for (const pr of pullRequests) {
      const status = await api.fetchCombinedRefStatus(
        repository.owner.login,
        repository.name,
        pr.head.sha
      )

      pullRequestsStatuses.push({
        state: status.state,
        totalCount: status.total_count,
        pullRequestId: pr.id,
        sha: pr.head.sha,
      })
    }

    await this.writePullRequestStatus(pullRequestsStatuses)

    return await this.getPullRequestStatuses(pullRequests, repository)
{'fraction_non_alphanumeric': 0.09519230769230769, 'fraction_numerical': 0.0, 'mean_word_length': 3.44076840981857, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6121889', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1149, 'n_words': 278}