Coder Social home page Coder Social logo

githubsync's Introduction

GitHubSync

Build status NuGet Status NuGet Status

A tool to help synchronizing specific files and folders across repositories

See Milestones for release notes.

.net API

NuGet package

https://nuget.org/packages/GitHubSync/

Usage

// Create a new RepoSync
var repoSync = new RepoSync(
    log: Console.WriteLine);

// Add source repo(s)
repoSync.AddSourceRepository(new(
    // Valid credentials for the source repo and all target repos
    credentials: octokitCredentials,
    owner: "UserOrOrg",
    repository: "TheSingleSourceRepository",
    branch: "master"));

// Add sources(s), only allowed when SyncMode == ExcludeAllByDefault
repoSync.AddBlob("sourceFile.txt");
repoSync.AddBlob("code.cs");

// Remove sources(s), only allowed when SyncMode == IncludeAllByDefault
repoSync.AddBlob("sourceFile.txt");
repoSync.AddBlob("code.cs");

// Add target repo(s)
repoSync.AddTargetRepository(new(
    credentials: octokitCredentials,
    owner: "UserOrOrg",
    repository: "TargetRepo1",
    branch: "master"));

repoSync.AddTargetRepository(new(
    credentials: octokitCredentials,
    owner: "UserOrOrg",
    repository: "TargetRepo2",
    branch: "master"));

// Run the sync
await repoSync.Sync(syncOutput: SyncOutput.MergePullRequest);

snippet source | anchor

dotnet Tool

This tool allows reading the configuration from a file. This allows customization of the templates and repositories without having to recompile any code.

Installation

Ensure dotnet CLI is installed.

Install GitHubSync.Tool

dotnet tool install -g GitHubSync.Tool

Usage

Run against the current directory will use githubsync.yaml in the current directory:

githubsync

Run against a specific config file:

githubsync C:\Code\Project\sync.yaml

Configuration definition

The configuration format is yaml. There should be 1 to n number of templates and 1 to n number of (target) repositories.

templates:
  - name: [template name]
    url: [repository url of the template]
    branch: [branch to use, defaults to `master`]
    
repositories:
  - name: [repository name]
    url: [repository url of the target repository]
    branch: [target branch, defaults to `master`]
    autoMerge: [true / false, true is only used when user is allowed to merge PRs on the target repository]
    templates:
      - [list of template names to use in the order to apply]

Example

templates:
  - name: geertvanhorrik
    url: https://github.com/geertvanhorrik/repositorytemplate
    branch: master
  - name: catel
    url: https://github.com/Catel/RepositoryTemplate.Components
    branch: master
  - name: wildgums-components-public
    url: https://github.com/wildgums/RepositoryTemplate.Components.Public
    branch: master
repositories:
  - name: CsvHelper
    url: https://github.com/JoshClose/CsvHelper
    branch: master
    autoMerge: false
    templates:
      - geertvanhorrik
  - name: Catel
    url: https://github.com/catel/catel
    branch: develop
    autoMerge: true
    templates:
      - geertvanhorrik
      - catel
  - name: Orc.Controls
    url: https://github.com/wildgums/orc.controls
    branch: develop
    autoMerge: true
    templates:
      - geertvanhorrik
      - wildgums-components-public

This example will result in the following:

  • CsvHelper => use geertvanhorrik
  • Catel => use geertvanhorrik + catel (combined, so catel can override files)
  • Orc.Controls => use geertvanhorrik + wildgums-components-public (combined, so wildgums-components-public can override files)

Icon

Sync designed by Edward Boatman from The Noun Project.

githubsync's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

githubsync's Issues

Allow yaml configuration files to drive the sync engine

I've written a simple wrapper around this library that creates a configuration similar to the one below:

templates:
  - name: geertvanhorrik
    url: https://github.com/geertvanhorrik/repositorytemplate
    branch: master
  - name: catel
    url: https://github.com/Catel/RepositoryTemplate.Components
    branch: master
  - name: wildgums-components-public
    url: https://github.com/wildgums/RepositoryTemplate.Components.Public
    branch: master

repositories:
  - name: CsvHelper
    url: https://github.com/JoshClose/CsvHelper
    branch: master
    autoMerge: false
    templates:
      - geertvanhorrik

  - name: Catel
    url: https://github.com/catel/catel
    branch: develop
    autoMerge: true
    templates:
      - geertvanhorrik
      - catel

  - name: Orc.Controls
    url: https://github.com/wildgums/orc.controls
    branch: develop
    autoMerge: true
    templates:
      - geertvanhorrik
      - wildgums-components-public

This way, you can create large lists of synchronizations without having to modify any code. Would you be interested in having this in GitHubSync?

PR+Merge branch doesnt get automatically deleted

When using the CLI tool to sync repos using autoMerge: true, it creates a branch with a PR for the changes, then automatically merges it (this works fine). However once it's done, it leaves the branch still in the repository.

After some time this builds up and it's a pain to manually delete them one by one (x15 repos)
screenshot

can you add an option for keepMergeBranch: true/false ? or otherwise make it auto delete the branch once it's done? There's no reason for it to stay.

Thanks!

Ignore/Exclude specific files/glob's from sync

Hi

It would be really useful to me if i could exclude certain files from syncronising. For example we have many microservice API repo's, all of which use a Template Repository to sync common properties/github workflows. for the github workflows specifically is where we have an issue.

Because our template repository has a workflow to sync to all other repo's when changed, this workflow also then gets pushed to all repositories. meaning we need an ugly if repository == 'githubuser/repo' in each action.

What i propose is adding a list property to the configuration like so:

templates:
  - name: [template name]
    url: [repository url of the template]
    branch: [branch to use, defaults to `master`]
    exclude:
        - '.github/**/*'
        - 'my_super_secret_file.yml'
    
repositories:
  - name: [repository name]
    url: [repository url of the target repository]
    branch: [target branch, defaults to `master`]
    autoMerge: [true / false, true is only used when user is allowed to merge PRs on the target repository]
    templates:
      - [list of template names to use in the order to apply]

I did fork the project and try to add this myself and submit a PR, but i found the code structure very difficult to follow, so perhaps its easier for you to add? It would be really useful though :)

Allow sync to support multiple source repositories

At the moment, RepoSync only supports a single source repository. Would you be interested if I add support for multiple source repositories?

E.g.

AddSourceRepository(string organization, string repository, string branch);

Then I can loop them backwards:

for (int i = _sourceRepos.Count - 1; i >= 0; i--)
{
    // clone files (if not already cloned)
}

Cannot create PR on external repository

Today I tried to include an "external" (read: I am not an owner) to the list of repositories to sync (even "just" creating a PR). However, when it needs to create the blob, it fails with a NotFound.

I think in such a case, it needs to fork instead.

clean up syncomatic branches

for branches we decide not to merge it would be good to have a feature to clean them up.

Perhaps delete all Syncomatic-* branches older than X days??

Or delete all but the most current?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.