Skip to content

Commit

Permalink
Add --dry-run to preview changes to PR (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer authored Oct 14, 2024
1 parent 1a58bba commit ee9ca57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ release *OPTIONS:
git-check --check-repo=1 {{SETUP_BEND_PATH}}; \
make-release {{OPTIONS}}

# Set milestone for PR in dry-run mode
dry-run *OPTIONS:
@overlay use {{ join(SETUP_BEND_PATH, 'nu', 'milestone.nu') }}; \
milestone-update --dry-run {{OPTIONS}}

# Plugins need to be registered only once after nu v0.61
_setup:
@register -e json {{ join(NU_DIR, _query_plugin) }}
15 changes: 12 additions & 3 deletions nu/milestone.nu
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@ export def 'milestone-update' [
--milestone(-m): string, # Milestone name
--pr: string, # The PR number/url/branch of the PR that we want to add milestone.
--force(-f), # Force update milestone even if the milestone is already set.
--dry-run(-d), # Dry run, only print the milestone that would be set.
] {
if not (is-installed 'gh') {
print 'gh command not found, please install it first, see: https://cli.github.com/.'
exit $ECODE.MISSING_BINARY
}
if ($gh_token | is-not-empty) { $env.GH_TOKEN = $gh_token }
let selected = if ($milestone | is-empty) { guess-milestone $repo $pr } else { $milestone }
if $force { gh pr edit $pr --repo $repo --remove-milestone }
print $'(char nl)Setting milestone to (ansi p)($selected)(ansi reset) for PR ($pr) in repository ($repo)...'
if $force {
if $dry_run {
print $'(char nl)Would remove milestone for PR (ansi p)($pr)(ansi reset) in repository (ansi p)($repo)(ansi reset) ...'
} else {
gh pr edit $pr --repo $repo --remove-milestone
}
}
print $'(char nl)Setting milestone to (ansi p)($selected)(ansi reset) for PR (ansi p)($pr)(ansi reset) in repository (ansi p)($repo)(ansi reset) ...'
# FIXME: GraphQL: Resource not accessible by integration (updatePullRequest)
gh pr edit $pr --repo $repo --milestone $selected
if not $dry_run {
gh pr edit $pr --repo $repo --milestone $selected
}
}

# Guess milestone by the merged date of the PR and the infomation of open milestones.
Expand Down

0 comments on commit ee9ca57

Please sign in to comment.