forked from projen/projen
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mergify rule that will merge automatically for a single approver and "build" job passes.
- Loading branch information
Elad Ben-Israel
committed
May 18, 2020
1 parent
2207ef3
commit 5974506
Showing
6 changed files
with
114 additions
and
4 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
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,14 @@ | ||
# Generated by projen. To modify, edit .projenrc.js and run "npx projen". | ||
|
||
pull_request_rules: | ||
- name: Automatic merge on approval and successful build | ||
conditions: | ||
- "#approved-reviews-by>=1" | ||
- status-success=build | ||
actions: | ||
merge: | ||
method: squash | ||
commit_message: title+body | ||
strict: smart | ||
strict_method: merge | ||
delete_head_branch: {} |
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
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
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,32 @@ | ||
import { Construct } from 'constructs'; | ||
import { Project } from './project'; | ||
import { YamlFile } from './yaml'; | ||
|
||
export interface MergifyRule { | ||
readonly name: string; | ||
readonly conditions: string[]; | ||
readonly actions: { [action: string]: any }; | ||
} | ||
|
||
export interface MergifyOptions { | ||
readonly rules?: MergifyRule[]; | ||
} | ||
|
||
export class Mergify extends Construct { | ||
private readonly rules = new Array<MergifyRule>(); | ||
|
||
constructor(project: Project) { | ||
super(project, 'mergify'); | ||
|
||
new YamlFile(project, '.mergify.yml', { | ||
committed: true, // must be committed for mergify to be able to find it dah! | ||
obj: { | ||
pull_request_rules: this.rules, | ||
}, | ||
}); | ||
} | ||
|
||
public addRule(rule: MergifyRule) { | ||
this.rules.push(rule); | ||
} | ||
} |
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,24 @@ | ||
import { JsonFile, JsonFileOptions } from './json'; | ||
import * as YAML from 'yaml'; | ||
import { Project } from './project'; | ||
import { GENERATION_DISCLAIMER } from './common'; | ||
|
||
export interface YamlFileOptions extends JsonFileOptions { | ||
|
||
} | ||
|
||
export class YamlFile extends JsonFile { | ||
constructor(project: Project, filePath: string, options: YamlFileOptions) { | ||
super(project, filePath, options); | ||
} | ||
|
||
protected get data() { | ||
// sanitize object references by serializaing and deserializing to JSON | ||
const sanitized = JSON.parse(JSON.stringify(this.obj)); | ||
return [ | ||
`# ${GENERATION_DISCLAIMER}`, | ||
'', | ||
YAML.stringify(sanitized, { indent: 2 }), | ||
].join('\n') | ||
} | ||
} |