Skip to content

Commit 5c59eeb

Browse files
committed
docs: update README and CONTRIBUTING
1 parent bd83861 commit 5c59eeb

File tree

5 files changed

+357
-42
lines changed

5 files changed

+357
-42
lines changed

.github/CONTRIBUTING.md

+202-20
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,217 @@
1-
## Contributing
1+
# Contributing to Pull
22

33
Hi there! We're thrilled that you'd like to contribute to this project. Your
44
help is essential for keeping it great.
55

66
Please note that this project is released with a
7-
[Contributor Code of Conduct][code-of-conduct]. By participating in this project
8-
you agree to abide by its terms.
7+
[Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this
8+
project you agree to abide by its terms.
99

10-
## Submitting a pull request
10+
## Development Environment
11+
12+
### Prerequisites
13+
14+
- [Deno](https://deno.land/#installation) 2.0.6 or later
15+
- MongoDB 8.0
16+
- Redis 7.4
17+
18+
### Development Containers
19+
20+
We provide two development environments:
21+
22+
1. Base Environment:
23+
24+
```bash
25+
devcontainer open .devcontainer/pull-base
26+
```
27+
28+
2. Full Environment (includes monitoring tools which supports amd64 only):
29+
30+
```bash
31+
devcontainer open .devcontainer/pull-full
32+
```
33+
34+
The full environment includes additional tools:
35+
36+
- Mongo Express (port 8081)
37+
- Redis Commander (port 8082)
38+
- Bull Board (port 8083)
39+
40+
## Getting Started
41+
42+
1. Fork and clone the repository
43+
2. Make sure you have [Deno](https://deno.land/#installation) installed
44+
3. Install development hooks:
45+
```bash
46+
deno task install-hooks
47+
```
48+
4. Set up your GitHub App. Follow the
49+
[Probot documentation](https://probot.github.io/docs/development/) for
50+
detailed instructions on creating a GitHub App.
51+
5. Set up your environment variables by copying the `.env.example` file to
52+
`.env` and filling in the required values:
53+
```sh
54+
cp .env.example .env
55+
```
56+
6. Start the development server:
57+
```bash
58+
deno task dev
59+
```
60+
Start the development worker:
61+
```bash
62+
deno task worker
63+
```
64+
65+
## Available Scripts
66+
67+
- `deno task dev`: Start the app in development mode
68+
- `deno task dev:skip-full-sync`: Start without initial full sync
69+
- `deno task worker`: Start the background worker
70+
- `deno task test`: Run tests
71+
- `deno task check`: Run linter and formatter checks
72+
- `deno task full-sync`: Run full repository sync
73+
- `deno task manual-process <owner>/<repo>`: Process specific repository
74+
75+
## Application Architecture
76+
77+
### Core Components
78+
79+
#### 1. Web Server (`src/index.ts`)
80+
81+
The main Express.js application that:
82+
83+
- Handles GitHub webhooks
84+
- Serves API endpoints
85+
- Initializes the scheduler
86+
87+
#### 2. Background Worker (`src/worker.ts`)
88+
89+
Processes repository sync jobs using BullMQ:
90+
91+
- Handles job concurrency
92+
- Manages retries and failures
93+
- Processes jobs based on priority
94+
95+
#### 3. Scheduler ([`@wei/probot-scheduler`](https://jsr.io/@wei/probot-scheduler))
96+
97+
Manages periodic repository checks:
98+
99+
- Schedules jobs using cron expressions
100+
- Maintains job queues in Redis
101+
- Handles job priorities and scheduling
102+
103+
#### 4. Database Layer
104+
105+
- **MongoDB**: Stores repository and installation data
106+
- **Redis**: Manages job queues and caching
107+
- **Connections**: Managed through `src/configs/database.ts` and
108+
`src/configs/redis.ts`
109+
110+
#### 5. Pull Processor (`src/processor/pull.ts`)
111+
112+
The Pull processor is the core component that handles repository
113+
synchronization. Here's a detailed breakdown of its functionality:
114+
115+
```mermaid
116+
graph TD
117+
A[Routine Check] --> B{Has Diff?}
118+
B -->|Yes| C{Existing PR?}
119+
B -->|No| D[Skip]
120+
C -->|Yes| E[Check Auto Merge]
121+
C -->|No| F[Create PR]
122+
F --> E
123+
E --> G{Mergeable?}
124+
G -->|Yes| H[Process Merge]
125+
G -->|No| I[Handle Conflict]
126+
```
127+
128+
##### Main Components
129+
130+
1. **Routine Check (`routineCheck`):**
131+
- Iterates through configured rules in `pull.yml`
132+
- For each rule:
133+
- Normalizes base and upstream branch names
134+
- Checks for differences between branches
135+
- Creates or updates pull requests as needed
136+
137+
2. **Difference Detection (`hasDiff`):**
138+
- Compares commits between base and upstream branches
139+
- Handles special cases:
140+
- Large diffs that timeout
141+
- Missing branches
142+
- No common ancestor
143+
- Returns true if changes are detected
144+
145+
3. **Pull Request Management:**
146+
- **Updates (`getOpenPR`):**
147+
- Finds existing PRs created by the bot
148+
- Validates PR matches current sync rule
149+
- **Creation (`createPR`):**
150+
- Creates new pull request with standardized title
151+
- Assigns reviewers and labels
152+
- Updates PR body with tracking information
153+
154+
4. **Merge Process (`checkAutoMerge`, `processMerge`):**
155+
- Supports multiple merge methods:
156+
- `none`: No automatic merging
157+
- `merge`: Standard merge commit
158+
- `squash`: Squash and merge
159+
- `rebase`: Rebase and merge
160+
- `hardreset`: Force push to base branch
161+
- Handles merge conflicts:
162+
- Adds conflict label
163+
- Assigns conflict reviewers
164+
- Updates PR status
165+
166+
##### Error Handling
167+
168+
The processor implements robust error handling:
169+
170+
- Retries for mergeable status checks
171+
- Graceful handling of GitHub API limitations
172+
- Detailed logging for debugging
173+
- Conflict resolution workflows
174+
175+
##### Best Practices
176+
177+
When modifying the Pull processor:
178+
179+
1. Maintain idempotency in operations
180+
2. Implement proper error handling
181+
3. Add detailed logging for debugging
182+
4. Consider edge cases
183+
184+
## Submitting a Pull Request
11185

12-
1. [Fork][fork] and clone the repository
13-
1. Make sure you have [Deno installed](https://deno.land/#installation)
14-
1. Make sure the tests pass on your machine: `deno test`
15186
1. Create a new branch: `git checkout -b my-branch-name`
16-
1. Make your change, add tests, and make sure the tests still pass
17-
1. Make sure the code is formatted: `deno fmt`
18-
1. Make sure the linter passes on your machine: `deno lint`
19-
1. Push to your fork and [submit a pull request][pr]
20-
1. Pat your self on the back and wait for your pull request to be reviewed and
21-
merged.
187+
2. Make your changes
188+
3. Make sure the tests pass:
189+
```bash
190+
deno test
191+
```
192+
4. Format your code:
193+
```bash
194+
deno fmt
195+
```
196+
5. Run the linter:
197+
```bash
198+
deno lint
199+
```
200+
6. Push to your fork and submit a pull request
201+
7. Pat yourself on the back and wait for your pull request to be reviewed and
202+
merged
22203

23204
Here are a few things you can do that will increase the likelihood of your pull
24205
request being accepted:
25206

26207
- Follow the style guide enforced by Deno's built-in formatter. You can format
27208
your code by running `deno fmt`
28-
- Write and update tests.
29-
- Keep your change as focused as possible. If there are multiple changes you
209+
- Write and update tests
210+
- Keep your changes as focused as possible. If there are multiple changes you
30211
would like to make that are not dependent upon each other, consider submitting
31-
them as separate pull requests.
212+
them as separate pull requests
32213
- Write a
33-
[good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
214+
[good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
34215

35216
Work in Progress pull requests are also welcome to get feedback early on, or if
36217
there is something blocked you.
@@ -42,6 +223,7 @@ there is something blocked you.
42223
- [GitHub Help](https://help.github.com)
43224
- [Deno Manual](https://deno.land/manual)
44225

45-
[fork]: ../../../fork
46-
[pr]: ../../../compare
47-
[code-of-conduct]: CODE_OF_CONDUCT.md
226+
## License
227+
228+
By contributing, you agree that your contributions will be licensed under its
229+
MIT License.

.github/dependabot.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66

77
version: 2
88
updates:
9-
- package-ecosystem: "npm"
10-
directory: "/"
11-
schedule:
12-
interval: "daily"
139
- package-ecosystem: "github-actions"
1410
directory: "/"
1511
schedule:
16-
interval: "daily"
12+
interval: "weekly"
1713
- package-ecosystem: "devcontainers"
1814
directory: "/"
1915
schedule:
20-
interval: weekly
16+
interval: "weekly"

LICENSE

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
The MIT License
22

3-
Copyright (c) 2024 Wei He <[email protected]>
3+
Copyright (c) 2024 Wei He <https://wei.mit-license.org>
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)