feat: New branch and sha1 repository settings

- `repository`: Branch name in the local clone to check out
- `sha1`: An explicit revision to reset to.

Fixes #27
pull/108/head
Robert Dailey 2 years ago
parent e27659e3f9
commit 8266410092

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
YAML format, ready to copy & paste. YAML format, ready to copy & paste.
- Docker: New `edge` tag for experimental and potentially unstable builds on `master`. Includes both - Docker: New `edge` tag for experimental and potentially unstable builds on `master`. Includes both
the latest Docker and Recyclarr changes to allow users to try them out before an official release. the latest Docker and Recyclarr changes to allow users to try them out before an official release.
- Settings: New `branch` and `sha1` Repository settings. (#27)
### Changed ### Changed

@ -1,24 +1,12 @@
{ {
"$schema": "http://json-schema.org/draft-06/schema#", "$schema": "https://json-schema.org/draft-07/schema",
"$ref": "#/definitions/Settings", "$id": "https://raw.githubusercontent.com/recyclarr/recyclarr/master/schemas/settings-schema.json",
"definitions": { "type": "object",
"Settings": { "title": "Recyclarr Settings",
"type": "object", "description": "Optional settings to control the behavior of Recyclarr",
"additionalProperties": false, "additionalProperties": false,
"title": "Recyclarr Settings", "properties": {
"description": "Optional settings to control the behavior of Recyclarr", "repository": {
"properties": {
"repository": {
"$ref": "#/definitions/Repository"
},
"enable_ssl_certificate_validation": {
"type": "boolean",
"title": "Allow SSL certificate validation for Sonarr & Radarr",
"description": "If set to `false`, SSL certificates are not validated. This is useful if you are connecting to a Sonarr or Radarr instance using `https` and it is set up with self-signed certificates. Note that disabling this setting is a **security risk** and should be avoided unless you are absolutely sure what you are doing."
}
}
},
"Repository": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"title": "Settings for the git repo", "title": "Settings for the git repo",
@ -26,20 +14,26 @@
"properties": { "properties": {
"clone_url": { "clone_url": {
"type": "string", "type": "string",
"title": "Clone URL to the trash guides git repository",
"description": "A URL compatible with `git clone` that is used to clone the Trash Guides repository. This setting exists for enthusiasts that may want to instead have Recyclarr pull data from a fork instead of the official repository.",
"format": "uri", "format": "uri",
"qt-uri-protocols": [ "title": "Clone URL to the trash guides git repository",
"http", "description": "A URL compatible with `git clone` that is used to clone the Trash Guides repository. This setting exists for enthusiasts that may want to instead have Recyclarr pull data from a fork instead of the official repository."
"https", },
"ssh", "branch": {
"git" "type": "string",
], "title": "The name of a branch to check out in the repository"
"qt-uri-extensions": [ },
".git" "sha1": {
] "type": "string",
"title": "A SHA1 (commit hash) in Git to use",
"description": "If specified, it overrides the `branch` setting. This SHA1 is passed to `git reset --hard` to force your local clone to this specific revision in the repository. If not specified, only the `branch` controls what revision is used in the repo."
} }
} }
},
"enable_ssl_certificate_validation": {
"type": "boolean",
"title": "Allow SSL certificate validation for Sonarr & Radarr",
"description": "If set to `false`, SSL certificates are not validated. This is useful if you are connecting to a Sonarr or Radarr instance using `https` and it is set up with self-signed certificates. Note that disabling this setting is a **security risk** and should be avoided unless you are absolutely sure what you are doing.",
"default": false
} }
} }
} }

@ -3,6 +3,8 @@ namespace TrashLib.Config.Settings;
public record TrashRepository public record TrashRepository
{ {
public string CloneUrl { get; init; } = "https://github.com/TRaSH-/Guides.git"; public string CloneUrl { get; init; } = "https://github.com/TRaSH-/Guides.git";
public string Branch { get; init; } = "master";
public string? Sha1 { get; init; }
} }
public record SettingsValues public record SettingsValues

@ -54,16 +54,20 @@ public class RepoUpdater : IRepoUpdater
{ {
var repoSettings = _settingsProvider.Settings.Repository; var repoSettings = _settingsProvider.Settings.Repository;
var cloneUrl = repoSettings.CloneUrl; var cloneUrl = repoSettings.CloneUrl;
const string branch = "master"; var branch = repoSettings.Branch;
_log.Debug("Using Branch & Clone URL: {Branch}, {Url}", branch, cloneUrl); _log.Debug("Using Branch & Clone URL: {Branch}, {Url}", branch, cloneUrl);
if (repoSettings.Sha1 is not null)
{
_log.Warning("Using explicit SHA1 for local repository: {Sha1}", repoSettings.Sha1);
}
try try
{ {
using var repo = _repositoryFactory.CreateAndCloneIfNeeded(cloneUrl, RepoPath.FullName, branch); using var repo = _repositoryFactory.CreateAndCloneIfNeeded(cloneUrl, RepoPath.FullName, branch);
repo.ForceCheckout(branch); repo.ForceCheckout(branch);
repo.Fetch(); repo.Fetch();
repo.ResetHard($"origin/{branch}"); repo.ResetHard(repoSettings.Sha1 ?? $"origin/{branch}");
} }
catch (LibGit2SharpException e) catch (LibGit2SharpException e)
{ {

@ -1,3 +1,4 @@
using Common.Extensions;
using LibGit2Sharp; using LibGit2Sharp;
namespace VersionControl; namespace VersionControl;
@ -35,9 +36,10 @@ public sealed class GitRepository : IGitRepository
Commands.Fetch(_repo.Value, origin.Name, origin.FetchRefSpecs.Select(s => s.Specification), null, ""); Commands.Fetch(_repo.Value, origin.Name, origin.FetchRefSpecs.Select(s => s.Specification), null, "");
} }
public void ResetHard(string toBranch) public void ResetHard(string toBranchOrSha1)
{ {
var commit = _repo.Value.Branches[toBranch].Tip; var branch = _repo.Value.Branches.FirstOrDefault(b => b.FriendlyName.ContainsIgnoreCase(toBranchOrSha1));
var commit = branch is not null ? branch.Tip : _repo.Value.Lookup<Commit>(toBranchOrSha1);
_repo.Value.Reset(ResetMode.Hard, commit); _repo.Value.Reset(ResetMode.Hard, commit);
} }

@ -4,6 +4,6 @@ public interface IGitRepository : IDisposable
{ {
void ForceCheckout(string branch); void ForceCheckout(string branch);
void Fetch(string remote = "origin"); void Fetch(string remote = "origin");
void ResetHard(string toBranch); void ResetHard(string toBranchOrSha1);
void SetRemote(string name, string newUrl); void SetRemote(string name, string newUrl);
} }

@ -1,7 +1,8 @@
This page contains the YAML reference for Recyclarr settings. Settings support was introduced in This page contains the YAML reference for Recyclarr settings. Settings support was introduced in
version `1.7.0`. version `1.7.0`.
The `settings.yml` file is located in the following locations depending on your platform: The `settings.yml` file is located in the following locations (by default) depending on your
platform:
| Platform | Location | | Platform | Location |
| -------- | ------------------------------------------------------ | | -------- | ------------------------------------------------------ |
@ -36,6 +37,7 @@ page.
Table of Contents Table of Contents
- [Global Settings](#global-settings)
- [Repository Settings](#repository-settings) - [Repository Settings](#repository-settings)
## Global Settings ## Global Settings
@ -52,14 +54,27 @@ enable_ssl_certificate_validation: true
## Repository Settings ## Repository Settings
**NOTE**: Never edit files in the locally cloned repo managed by Recyclarr. It will always destroy
local changes in that repository.
```yml ```yml
repository: repository:
clone_url: https://github.com/TRaSH-/Guides.git clone_url: https://github.com/TRaSH-/Guides.git
branch: master
sha1: e27659e3f90d9b60c1f0b0f204b2530bb2299b41
``` ```
- `clone_url`<br> - `clone_url` *(Default: `https://github.com/TRaSH-/Guides.git`)*<br>
A URL compatible with `git clone` that is used to clone the [Trash Guides A URL compatible with `git clone` that is used to clone the [Trash Guides
repository][official_repo]. This setting exists for enthusiasts that may want to instead have repository][official_repo]. This setting exists for enthusiasts that may want to instead have
Recyclarr pull data from a fork instead of the official repository. Recyclarr pull data from a fork instead of the official repository.
- `branch` *(Default: `master`)*<br>
The name of a branch to check out in the repository.
- `sha1` *(Default: empty)*<br>
A SHA1 (commit hash) in Git to use. If specified, it overrides the `branch` setting. This SHA1 is
passed to `git reset --hard` to force your local clone to this specific revision in the
repository. If not specified, only the `branch` controls what revision is used in the repo.
[official_repo]: https://github.com/TRaSH-/Guides [official_repo]: https://github.com/TRaSH-/Guides

Loading…
Cancel
Save