Skip to content

Repository files navigation

Soenneker.GitHub.Repositories.Readmes

Create or replace a repository's README.md with a GitHub commit on the branch you choose.

Installation

dotnet add package Soenneker.GitHub.Repositories.Readmes

Configuration

{
  "GH": {
    "Token": "github-token"
  }
}

The token must have repository contents write access.

Registration

services.AddGitHubRepositoriesReadmesUtilAsSingleton();

Use AddGitHubRepositoriesReadmesUtilAsScoped() for a scoped consumer.

Usage

public sealed class RepositoryReadmeService
{
    private readonly IGitHubRepositoriesReadmesUtil _readmes;

    public RepositoryReadmeService(IGitHubRepositoriesReadmesUtil readmes)
    {
        _readmes = readmes;
    }

    public ValueTask Publish(
        string markdown,
        CancellationToken cancellationToken = default)
    {
        return _readmes.Upsert(
            owner: "soenneker",
            name: "example-repository",
            commitMessage: "Update README",
            content: markdown,
            branch: "main",
            cancellationToken);
    }
}
  • Create fails when README.md already exists.
  • Update reads the file's current SHA from the requested branch, then replaces its contents.
  • Upsert updates the file when present and creates it only when GitHub reports it missing.

Each successful call creates a commit. The supplied content replaces the entire file; it is not merged with the existing Markdown. The branch must already exist.

About

A utility library for GitHub repository readme related operations

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages