Skip to content

Commit

Permalink
feat: Add delete milestone by title or number support (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer authored Nov 3, 2024
1 parent 5baaa10 commit a67f768
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Description:
# - Delete a milestone by title or number.

name: Milestone Delete@develop
on:
workflow_dispatch:
inputs:
milestone:
required: true
description: 'Title / Number'

# Fix GraphQL: Resource not accessible by integration (updatePullRequest)
permissions:
contents: write
pull-requests: write

jobs:
delete-milestone:
runs-on: ubuntu-latest
name: Delete Milestone
steps:
- name: Delete Milestone
id: delete
uses: hustcer/milestone-action@develop
with:
action: delete
milestone: ${{ github.event.inputs.milestone }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add milestone to closed issues that have a merged PR fix automatically
- Create milestone by title, description and due date
- Close milestone by title or milestone number
- Delete milestone by title or milestone number

## Usage

Expand Down Expand Up @@ -71,15 +72,27 @@ Close milestone by title or milestone number:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Delete milestone by title or milestone number:
```yaml
- name: Delete Milestone
uses: hustcer/milestone-action@v2
with:
action: delete
milestone: v1.0 # Milestone title or number
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## Inputs
| Name | Type | Description |
| ------------ | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| action | String | Action to perform: create, close, bind-pr, bind-issue, defaults to `bind-pr` |
| action | String | Action to perform: create, close, delete, bind-pr, bind-issue, defaults to `bind-pr` |
| title | String | Title of the milestone to create |
| due-on | String | Due date of the milestone (yyyy-mm-dd) to create |
| description | String | Description of the milestone to create |
| milestone | String | Title or number of the milestone to close, could also be used to specify the milestone title to bind to the PR or issue |
| milestone | String | Title or number of the milestone to close or delete, could also be used to specify the milestone title to bind to the PR or issue |
| force | Boolean | If the PR or Issue already has a milestone just remove it and set to a new one if they are different |
| github-token | String | The GitHub token to access the API for milestone management, defaults to `${{ github.token }}` |

Expand Down
17 changes: 15 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- 自动为已合并修复PR的关闭 issue 添加里程碑
- 通过标题、描述和截止日期创建里程碑
- 通过标题或里程碑编号关闭里程碑
- 通过标题或里程碑编号删除里程碑

## 使用方法

Expand Down Expand Up @@ -69,15 +70,27 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
通过标题或里程碑编号删除里程碑:
```yaml
- name: Delete Milestone
uses: hustcer/milestone-action@v2
with:
action: delete
milestone: v1.0 # Milestone title or number
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## 输入参数
| 名称 | 类型 | 描述 |
| ------------ | ------- | ---------------------------------------------------------------------------- |
| action | String | 要执行的操作, 可能的值未:create, close, bind-pr, bind-issue,默认为 `bind-pr` |
| action | String | 要执行的操作, 可能的值未:create, close, delete, bind-pr, bind-issue,默认为 `bind-pr`|
| title | String | 要创建的里程碑标题 |
| due-on | String | 要创建的里程碑的截止日期(yyyy-mm-dd) |
| description | String | 要创建的里程碑描述信息 |
| milestone | String | 要关闭的里程碑标题或编号,也可用于指定要绑定到 PR 或 issue 的里程碑标题 |
| milestone | String | 要关闭或删除的里程碑标题或编号,也可用于指定要绑定到 PR 或 issue 的里程碑标题 |
| force | Boolean | 如果 PR 或 Issue 已有里程碑,且与新的不同,则移除旧的并设置新的 |
| github-token | String | 用于访问 API 进行里程碑管理的 GitHub Token,默认为 `${{ github.token }}` |

Expand Down
4 changes: 2 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inputs:
action:
required: false
default: 'bind-pr'
description: 'The action to perform, should be bind-pr,bind-issue,create or close. Defaults to bind-pr.'
description: 'The action to perform, should be bind-pr,bind-issue,create, delete or close. Defaults to bind-pr.'
title:
required: false
default: '1.0.0'
Expand All @@ -48,7 +48,7 @@ inputs:
milestone:
required: false
default: ''
description: 'The milestone to set. If not provided, will try to guess a milestone.'
description: 'The milestone to set, close or delete.'
github-token:
required: false
default: '${{ github.token }}'
Expand Down
24 changes: 24 additions & 0 deletions nu/milestone.nu
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# [x] Support dry run mode
# [x] Create milestone by title, due_on, and description
# [x] Close milestone by title or number
# [x] Delete milestone by title or number
# [x] Add milestone to issue that has been fixed by a PR
# Description: Scripts for Github milestone management.

Expand Down Expand Up @@ -209,6 +210,28 @@ export def close-milestone [
echo $'milestone-number=($milestone.number)' o>> $env.GITHUB_OUTPUT
}

# Delete milestone for a repository by title or number.
export def delete-milestone [
repo: string, # Github repository name
milestone: string, # Milestone name or number
--gh-token(-t): string, # Github access token
] {
check-gh
if ($gh_token | is-not-empty) { $env.GH_TOKEN = $gh_token }
let milestoneId = if ($milestone | is-int) { $milestone } else {
let milestones = gh api $'/repos/($repo)/milestones' | from json
let milestone = $milestones | where title == $milestone
if ($milestone | is-empty) {
print 'Milestone not found.'; exit $ECODE.INVALID_PARAMETER
}
$milestone.0.number
}
let result = gh api -X DELETE $'/repos/($repo)/milestones/($milestoneId)'
let response = $result | from json
print $'Milestone with NO. (ansi p)($milestone.number)(ansi reset) was deleted with response:'
$response | table -e | print
}

def is-int [] {
$in | str trim | str replace -ar '\d' '' | is-empty
}
Expand Down Expand Up @@ -236,6 +259,7 @@ export def milestone-action [
] {
match $action {
close => { close-milestone $repo $milestone --gh-token $gh_token },
delete => { delete-milestone $repo $milestone --gh-token $gh_token },
create => { create-milestone $repo $title --due-on $due_on -D $description -t $gh_token },
bind-pr => { milestone-bind-for-pr $repo -t $gh_token -m $milestone --pr $pr --force=$force --dry-run=$dry_run },
bind-issue => { milestone-bind-for-issue $repo -t $gh_token -m $milestone --issue ($issue | into int) --force=$force --dry-run=$dry_run },
Expand Down

0 comments on commit a67f768

Please sign in to comment.