Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions action/check-issue/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ inputs:
description: "Repository for the vouched file in 'owner/repo' format (default: same as repo)."
required: false
default: ""
template-file:
description: "An optional path to a response template to use for unvouched users."
required: false
default: ""

outputs:
status:
Expand All @@ -52,6 +56,7 @@ runs:
--repo "${{ inputs.repo || github.repository }}"
--vouched-repo "${{ inputs.vouched-repo }}"
--vouched-file "${{ inputs.vouched-file }}"
--template-file "${{ inputs.template-file }}"
--require-vouch=${{ inputs.require-vouch }}
--auto-close=${{ inputs.auto-close }}
--dry-run=${{ inputs.dry-run }}
Expand Down
5 changes: 5 additions & 0 deletions action/check-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ inputs:
description: "Repository for the vouched file in 'owner/repo' format (default: same as repo)."
required: false
default: ""
template-file:
description: "An optional path to a response template to use for unvouched users."
required: false
default: ""

outputs:
status:
Expand All @@ -52,6 +56,7 @@ runs:
--repo "${{ inputs.repo || github.repository }}"
--vouched-repo "${{ inputs.vouched-repo }}"
--vouched-file "${{ inputs.vouched-file }}"
--template-file "${{ inputs.template-file }}"
--require-vouch=${{ inputs.require-vouch }}
--auto-close=${{ inputs.auto-close }}
--dry-run=${{ inputs.dry-run }}
Expand Down
53 changes: 53 additions & 0 deletions tests/template.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std/assert

use ../vouch/template.nu

export def "test default github unvouched PR template" [] {
let want = 'Hi @unvouched, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/mitchellh/vouch/blob/main/CONTRIBUTING.md for more details.
'

let pr_author = "unvouched"
let repo_parts = {
owner: "mitchellh",
name: "vouch",
}
let default_branch = "main";

const template_file = path self ../vouch/templates/github-pr-unvouched
let got = {
author: $pr_author,
owner: $repo_parts.owner,
repo: $repo_parts.name,
default_branch: $default_branch,
} | template render $template_file

assert equal $want $got
}

export def "test default github unvouched issue template" [] {
let want = 'Hi @unvouched, thanks for your interest!

This project requires that issue reporters are vouched, and you are not in the list of vouched users.

This issue will be closed automatically. See https://github.com/mitchellh/vouch/blob/main/CONTRIBUTING.md for more details.
'

let issue_author = "unvouched"
let owner = "mitchellh"
let repo_name = "vouch"
let default_branch = "main";

const template_file = path self ../vouch/templates/github-issue-unvouched
let got = {
author: $issue_author,
owner: $owner,
repo: $repo_name,
default_branch: $default_branch,
} | template render $template_file

assert equal $want $got
}
52 changes: 42 additions & 10 deletions vouch/github.nu
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use lib.nu [
remove-user
]

use template.nu
const pr_template = path self ./templates/github-pr-unvouched
const issue_template = path self ./templates/github-issue-unvouched

# Check if a PR author is a vouched contributor.
#
# This checks if the PR author is:
Expand All @@ -24,6 +28,18 @@ use lib.nu [
#
# When --auto-close is true and user is unvouched/denounced, the PR is closed.
#
# --template-file can be used to supply a path to a custom template, which
# follows the string convention as seen in Nushell's "format pattern". Note the
# following template arguments are supported:
#
# * {author} - The pull request author
# * {owner} - The repository owner
# * {repo} - The repository name
# * {default_branch} - The repository default branch
#
# See "vouch/templates/github-pr-unvouched" for the default PR template, which
# can be used as an example.
#
# Outputs status: "skipped" (bot), "vouched", "allowed", or "closed".
#
# Examples:
Expand All @@ -42,6 +58,7 @@ export def gh-check-pr [
--repo (-R): string, # Repository in "owner/repo" format (required)
--vouched-repo: string, # Repository for the vouched file (defaults to --repo)
--vouched-file: string = ".github/VOUCHED.td", # Path to vouched contributors file in the repo
--template-file: string = $pr_template, # Optional path to response template to use for unvouched users
--require-vouch = true, # Require users to be vouched (false = only block denounced)
--auto-close = false, # Automatically close PRs from unvouched/denounced users
--dry-run = true, # Print what would happen without making changes
Expand Down Expand Up @@ -117,11 +134,12 @@ export def gh-check-pr [

print "Closing PR"

let message = $"Hi @($pr_author), thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/($repo_parts.owner)/($repo_parts.name)/blob/($default_branch)/CONTRIBUTING.md for more details."
let message = {
author: $pr_author,
owner: $repo_parts.owner,
repo: $repo_parts.name,
default_branch: $default_branch,
} | template render (if ($template_file | is-not-empty) { $template_file } else $pr_template)

if $dry_run {
print "(dry-run) Would post comment and close PR"
Expand Down Expand Up @@ -152,6 +170,18 @@ This PR will be closed automatically. See https://github.com/($repo_parts.owner)
#
# When --auto-close is true and user is unvouched/denounced, the issue is closed.
#
# --template-file can be used to supply a path to a custom template, which
# follows the string convention as seen in Nushell's "format pattern". Note the
# following template arguments are supported:
#
# * {author} - The issue author
# * {owner} - The repository owner
# * {repo} - The repository name
# * {default_branch} - The repository default branch
#
# See "vouch/templates/github-issue-unvouched" for the default issue template,
# which can be used as an example.
#
# Outputs status: "skipped" (bot), "vouched", "allowed", or "closed".
#
# Examples:
Expand All @@ -170,6 +200,7 @@ export def gh-check-issue [
--repo (-R): string, # Repository in "owner/repo" format (required)
--vouched-repo: string, # Repository for the vouched file (defaults to --repo)
--vouched-file: string = ".github/VOUCHED.td", # Path to vouched contributors file in the repo
--template-file: string = $issue_template, # Optional path to response template to use for unvouched users
--require-vouch = true, # Require users to be vouched (false = only block denounced)
--auto-close = false, # Automatically close issues from unvouched/denounced users
--dry-run = true, # Print what would happen without making changes
Expand Down Expand Up @@ -250,11 +281,12 @@ export def gh-check-issue [

print "Closing issue"

let message = $"Hi @($issue_author), thanks for your interest!

This project requires that issue reporters are vouched, and you are not in the list of vouched users.

This issue will be closed automatically. See https://github.com/($owner)/($repo_name)/blob/($default_branch)/CONTRIBUTING.md for more details."
let message = {
author: $issue_author,
owner: $owner,
repo: $repo_name,
default_branch: $default_branch,
} | template render (if ($template_file | is-not-empty) { $template_file } else $issue_template)

if $dry_run {
print "(dry-run) Would post comment and close issue"
Expand Down
29 changes: 29 additions & 0 deletions vouch/template.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Template helper module.

# Template engine based off of Nushell's "format pattern".
#
# Only designed to be used in vouch code - not designed to be used externally.
#
# To use, pass the record set representing the template arguments into the
# command, with the path:
#
# { ... } | template render templates/example
#
# Example:
#
# # Render the GitHub PR unvouched template:
# const $template_file = path self ./templates/github-pr-unvouched
# {
# author: $pr_author,
# owner: $repo_parts.owner,
# repo: $repo_parts.name,
# default_branch: $default_branch,
# } | template render $template_file
#
export def render [
path: string, # The path of the template
]: record -> string {
let input = open --raw $path
let out = $in | format pattern $input
$out
}
5 changes: 5 additions & 0 deletions vouch/templates/github-issue-unvouched
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hi @{author}, thanks for your interest!

This project requires that issue reporters are vouched, and you are not in the list of vouched users.

This issue will be closed automatically. See https://github.com/{owner}/{repo}/blob/{default_branch}/CONTRIBUTING.md for more details.
5 changes: 5 additions & 0 deletions vouch/templates/github-pr-unvouched
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hi @{author}, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/{owner}/{repo}/blob/{default_branch}/CONTRIBUTING.md for more details.