Open5

GitHub CLIからGitHub Projectsを操作する

GANGANGANGAN
$ gh project --help
Work with GitHub Projects. Note that the token you are using must have 'project' scope, which is not set by default. You can verify your token scope by running 'gh auth status' and add the project scope by running 'gh auth refresh -s project'.

USAGE
  gh project <command> [flags]

AVAILABLE COMMANDS
  close:       Close a project
  copy:        Copy a project
  create:      Create a project
  delete:      Delete a project
  edit:        Edit a project
  field-create: Create a field in a project
  field-delete: Delete a field in a project
  field-list:  List the fields in a project
  item-add:    Add a pull request or an issue to a project
  item-archive: Archive an item in a project
  item-create: Create a draft issue item in a project
  item-delete: Delete an item from a project by ID
  item-edit:   Edit an item in a project
  item-list:   List the items in a project
  list:        List the projects for an owner
  mark-template: Mark a project as a template
  view:        View a project

INHERITED FLAGS
  --help   Show help for command

EXAMPLES
  $ gh project create --owner monalisa --title "Roadmap"
  $ gh project view 1 --owner cli --web
  $ gh project field-list 1 --owner cli
  $ gh project item-list 1 --owner cli

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

なるほど、scopeを広げれば使えるのか。

GANGANGANGAN

そのままだと予想通り怒られる。

$ gh project list  
error: your authentication token is missing required scopes [read:project]
To request it, run:  gh auth refresh -s read:project
GANGANGANGAN

experiment: gh project item-add

$ gh project item-add --help
Add a pull request or an issue to a project

USAGE
  gh project item-add [<number>] [flags]

FLAGS
  --format string   Output format: {json}
  --owner string    Login of the owner. Use "@me" for the current user.
  --url string      URL of the issue or pull request to add to the project

INHERITED FLAGS
  --help   Show help for command

EXAMPLES
  # add an item to monalisa's project "1"
  gh project item-add 1 --owner monalisa --url https://github.com/monalisa/myproject/issues/23

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual
GANGANGANGAN

--urlの短縮実験

  • examples通り:--url https://github.com/shinGangan/{repo}/issues/258
  • いけた:--url shinGangan/{repo}/issues/258
  • いけなかった:--url shinGangan/{repo}#258
    resource not found, please check the URL
  • いけなかった:--url shinGangan/{repo}/258
    resource not found, please check the URL

-> https://github.comはなくても良い
-> issues or pullsは明記する必要がある => numberだけではダメ

project optionsの追加

Q. custum fieldの値もCLIから設定できるのか?
A. --formatで良しなにやれるかもしれないが現状分からん。CLIでとりあえず追加だけする感じになるかな。