Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyTetrahedron committed Jun 27, 2024
1 parent c33307e commit 456e228
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ You'll need a GitLab access token with read-write access to all the repositories
./gitlab-scheduled-merge -t [GITLAB_TOKEN] --gitlab-base-url [BASE_URL]
```

Your repositories need to be configured for scheduled automerge by adding a config file to the tree, which defines the time windows during which scheduled MRs can be merged.
By default, this file is called `.merge-schedule.yml`.

`merge-schedule.yml`:
```
mergeWindows:
- schedule:
cron: '0 2 * * *' # cron schedule which specifies the start of each merge window
isoWeek: '@even' # optional, can be @even or @odd to restrict the cron schedule to even/odd week numbers, or an integer to restrict it to one specific week of the year
location: 'Europe/Zurich' # optional, specify the time zone to interpret the cron schedule
maxDelay: '1h' # duration for which the merge window remains active
```

The config file is taken from the source branch of the merge request that is to be scheduled.

If multiple schedules are specified, merge requests are merged if at least one of them is active.

Whenever a merge request is labeled with the correct label (by default `scheduled`), the application will find it and merge it if a merge window is currently active, or post a comment indicating when the next merge window takes place.

## License

BSD 3-Clause License
Expand Down
4 changes: 2 additions & 2 deletions task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (w MergeWindow) getNextActiveWindowStartTime(t time.Time) (time.Time, error
if w.Schedule.Location != "" {
l, err := time.LoadLocation(w.Schedule.Location)
if err != nil {
return time.Time{}, fmt.Errorf("Failed to load location for merge window: %w", err)
return time.Time{}, fmt.Errorf("failed to load location for merge window: %w", err)
}
location = l
}
Expand All @@ -164,7 +164,7 @@ func (w MergeWindow) getNextActiveWindowStartTime(t time.Time) (time.Time, error

sched, err := cron.ParseStandard(w.Schedule.Cron)
if err != nil {
return time.Time{}, fmt.Errorf("Failed to parse cron schedule: %w", err)
return time.Time{}, fmt.Errorf("failed to parse cron schedule: %w", err)
}

nextRun := sched.Next(earliestTime)
Expand Down

0 comments on commit 456e228

Please sign in to comment.