File size: 2,541 Bytes
1851bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use gh_workflow::generate::Generate;
use gh_workflow::*;
use indexmap::indexmap;
use serde_json::json;

/// Generate the stale issues and PRs workflow
pub fn generate_stale_workflow() {
    let workflow = Workflow::default()
        .name("Close Stale Issues and PR")
        .on(Event::default().add_schedule(Schedule::new("0 * * * *")))
        .permissions(
            Permissions::default()
                .issues(Level::Write)
                .pull_requests(Level::Write),
        )
        .env(Env::from(indexmap! {
            "DAYS_BEFORE_ISSUE_STALE".to_string() => json!("30"),
            "DAYS_BEFORE_ISSUE_CLOSE".to_string() => json!("7"),
            "DAYS_BEFORE_PR_STALE".to_string() => json!("5"),
            "DAYS_BEFORE_PR_CLOSE".to_string() => json!("10"),
        }))
        .add_job(
            "stale",
            Job::new("Stale Issues")
                .add_step(
                    Step::new("Mark Stale Issues").uses("actions", "stale", "v10")
                        .with(Input::from(indexmap! {
                            "stale-issue-label".to_string() => json!("state: inactive"),
                            "stale-pr-label".to_string() => json!("state: inactive"),
                            "stale-issue-message".to_string() => json!(r#"**Action required:** Issue inactive for ${{ env.DAYS_BEFORE_ISSUE_STALE }} days.
Status update or closure in ${{ env.DAYS_BEFORE_ISSUE_CLOSE }} days."#),
                            "close-issue-message".to_string() => json!("Issue closed after ${{ env.DAYS_BEFORE_ISSUE_CLOSE }} days of inactivity."),
                            "stale-pr-message".to_string() => json!(r#"**Action required:** PR inactive for ${{ env.DAYS_BEFORE_PR_STALE }} days.
Status update or closure in ${{ env.DAYS_BEFORE_PR_CLOSE }} days."#),
                            "close-pr-message".to_string() => json!("PR closed after ${{ env.DAYS_BEFORE_PR_CLOSE }} days of inactivity."),
                            "days-before-issue-stale".to_string() => json!("${{ env.DAYS_BEFORE_ISSUE_STALE }}"),
                            "days-before-issue-close".to_string() => json!("${{ env.DAYS_BEFORE_ISSUE_CLOSE }}"),
                            "days-before-pr-stale".to_string() => json!("${{ env.DAYS_BEFORE_PR_STALE }}"),
                            "days-before-pr-close".to_string() => json!("${{ env.DAYS_BEFORE_PR_CLOSE }}"),
                        })),
                ),
        );

    Generate::new(workflow)
        .name("stale.yml")
        .generate()
        .unwrap();
}