-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7dc9af7
Showing
47 changed files
with
14,822 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# GitHub App Details | ||
APP_ID= | ||
GITHUB_CLIENT_ID= | ||
GITHUB_CLIENT_SECRET= | ||
|
||
# Use `trace` to get verbose logging or `info` to show less | ||
LOG_LEVEL=debug | ||
|
||
# Auth configs | ||
NEXTAUTH_SECRET=bad-secret | ||
NEXTAUTH_URL=http://localhost:3000 | ||
|
||
# Go to https://smee.io/new set this to the URL that you are redirected to. | ||
WEBHOOK_PROXY_URL= | ||
WEBHOOK_SECRET= | ||
|
||
# Private key for the GitHub App | ||
PRIVATE_KEY= | ||
|
||
# Used for settings various configuration in the app | ||
NODE_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
commit-message: | ||
prefix: "chore" | ||
prefix-development: "chore" | ||
include: "scope" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Build Docker Image | ||
|
||
on: | ||
- push | ||
- workflow_dispatch | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build Docker image | ||
run: docker build -t repo-sync-app . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Run Jest Tests | ||
|
||
on: | ||
- push | ||
- workflow_dispatch | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Run Jest Tests | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
npm-debug.log | ||
*.pem | ||
!mock-cert.pem | ||
.env | ||
coverage | ||
build | ||
.next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Next.js: debug server-side", | ||
"type": "node-terminal", | ||
"request": "launch", | ||
"command": "npm run dev" | ||
}, | ||
{ | ||
"name": "Next.js: debug client-side", | ||
"type": "chrome", | ||
"request": "launch", | ||
"url": "http://localhost:3000" | ||
}, | ||
{ | ||
"name": "Next.js: debug full stack", | ||
"type": "node-terminal", | ||
"request": "launch", | ||
"command": "npm run dev", | ||
"serverReadyAction": { | ||
"pattern": "- Local:.+(https?://.+)", | ||
"uriFormat": "%s", | ||
"action": "debugWithChrome" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FROM node:18-alpine AS deps | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app | ||
|
||
COPY package.json package-lock.json ./ | ||
RUN npm install --production | ||
|
||
FROM node:18-alpine AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
|
||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
RUN npm run build | ||
|
||
FROM node:18-alpine AS runner | ||
RUN apk add --no-cache git | ||
WORKDIR /app | ||
|
||
ENV NODE_ENV production | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
|
||
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/package.json ./package.json | ||
|
||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
|
||
ENV PORT 3000 | ||
|
||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 GitHub Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Repo Sync App | ||
|
||
This project serves as a proof of concept for managing the synchronization of "private forks". | ||
|
||
An initial ADR can be found [here](https://docs.google.com/document/d/1QXYzp_62fsVPWlAdzD2_OcwGonO3vvmO0lVw4DgGtIc/edit?usp=sharing). | ||
|
||
## Getting Started Developing | ||
|
||
### Install dependencies | ||
|
||
```sh | ||
npm i | ||
``` | ||
|
||
### Create the GitHub App | ||
|
||
_This part is not fun_ | ||
|
||
1. Create a new `.env` file from the `.env.example` file | ||
2. Create a new GitHub App [here](https://github.com/settings/apps/new) | ||
3. Copy all the secrets, credentials, and IDs into the `.env` file | ||
|
||
### Select a smee.io channel | ||
|
||
Go to [smee.io](https://smee.io/new) and create a new channel. Copy the URL and paste it into the `WEBHOOK_PROXY_URL` environment variable in `.env`. | ||
|
||
### Start the application | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
## Setup | ||
|
||
You'll need to install the GitHub app on whatever organization you plan on contributing from. You should give it access to all repositories. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# This is a GitHub App Manifest. These settings will be used by default when | ||
# initially configuring your GitHub App. | ||
# | ||
# NOTE: changing this file will not update your GitHub App settings. | ||
# You must visit github.com/settings/apps/your-app-name to edit them. | ||
# | ||
# Read more about configuring your GitHub App: | ||
# https://probot.github.io/docs/development/#configuring-a-github-app | ||
# | ||
# Read more about GitHub App Manifests: | ||
# https://developer.github.com/apps/building-github-apps/creating-github-apps-from-a-manifest/ | ||
|
||
# The list of events the GitHub App subscribes to. | ||
# Uncomment the event names below to enable them. | ||
default_events: | ||
- installation_target | ||
- meta | ||
- branch_protection_rule | ||
- fork | ||
- public | ||
- push | ||
- repository | ||
- repository_dispatch | ||
- workflow_dispatch | ||
- workflow_job | ||
- workflow_run | ||
|
||
# The set of permissions needed by the GitHub App. The format of the object uses | ||
# the permission name for the key (for example, issues) and the access type for | ||
# the value (for example, write). | ||
# Valid values are `read`, `write`, and `none` | ||
default_permissions: | ||
# https://developer.github.com/v3/apps/permissions/#actions | ||
actions: write | ||
|
||
# Repository creation, deletion, settings, teams, and collaborators. | ||
# https://developer.github.com/v3/apps/permissions/#permission-on-administration | ||
administration: write | ||
|
||
# Repository contents, commits, branches, downloads, releases, and merges. | ||
# https://developer.github.com/v3/apps/permissions/#permission-on-contents | ||
contents: write | ||
|
||
# Search repositories, list collaborators, and access repository metadata. | ||
# https://developer.github.com/v3/apps/permissions/#metadata-permissions | ||
metadata: read | ||
|
||
# Commit statuses. | ||
# https://developer.github.com/v3/apps/permissions/#permission-on-statuses | ||
statuses: write | ||
|
||
# Manage access to an organization. | ||
# https://developer.github.com/v3/apps/permissions/#permission-on-statuses/#organization-administration | ||
organization_administration: read | ||
|
||
# Organization members and teams. | ||
# https://developer.github.com/v3/apps/permissions/#permission-on-members | ||
members: read | ||
|
||
# Manage a user's email addresses. | ||
# https://developer.github.com/v3/apps/permissions/#email-addresses | ||
email_addresses: read | ||
|
||
# The name of the GitHub App. Defaults to the name specified in package.json | ||
name: repo-sync-app | ||
|
||
# The homepage of your GitHub App. | ||
url: https://github.com/github-community-projects/repo-sync-app | ||
|
||
# A description of the GitHub App. | ||
description: A GitHub App that allows you to contribute upstream using a "private fork". | ||
|
||
# Set to true when your GitHub App is available to the public or false when it is only accessible to the owner of the app. Default: true | ||
public: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: "3.8" | ||
services: | ||
web: | ||
build: | ||
context: ./ | ||
target: runner | ||
volumes: | ||
- .:/app | ||
command: npm run dev | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
NODE_ENV: development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Architecture | ||
|
||
## Overview | ||
|
||
The project is a Node.js application that uses the [Probot framework](https://probot.github.io/) to listen for events from GitHub. It uses a GitHub App to perform elevated actions on behalf of the user while the user has little or no permissions at all. | ||
|
||
## Sequence Diagram | ||
|
||
```mermaid | ||
sequenceDiagram | ||
participant U as upstream *Public | ||
box github.com/your-organization | ||
participant F as fork *Public | ||
participant M as mirror *Private | ||
end | ||
U->>F: User forks upstream into Organization | ||
F-->>F: Bot creates branch protection rules | ||
F-->>F: User requests mirror to be made | ||
F->>M: Bot creates a mirror of the fork | ||
M-->>M: User merges into `default` branch | ||
M->>F: Bot automatically syncs mirror to fork | ||
F->>U: User opens PR to upstream | ||
``` | ||
|
||
## Components | ||
|
||
### UI | ||
|
||
The UI is built in nextjs with React Typescript. The main purpose of the UI is to provide a way for the user to request a mirror repository to be created. Every other part of the workflow can be achieved in GitHub or with the git CLI. | ||
|
||
### GitHub App | ||
|
||
The GitHub App is the main component of the project. It is responsible for listening to events from GitHub and performing actions on behalf of the user. It is also responsible for creating the mirror repository and syncing all changes between the fork and the mirror. | ||
|
||
### Node Server | ||
|
||
As part of the nextjs framework, it exposes a Node server we can use to run the GitHub App. This is the entry point for the application. It is responsible for loading the GitHub App and starting the server as well as performing git operations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
roots: ["<rootDir>/src/", "<rootDir>/test/"], | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testRegex: "(/__tests__/.*|\\.(test|spec))\\.[tj]sx?$", | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
testEnvironment: "node", | ||
moduleNameMapper: { | ||
"^@/bot/(.*)$": "<rootDir>/src/$1", | ||
"^@/utils/(.*)$": "<rootDir>/common/$1", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
Oops, something went wrong.