devshop/github-api-cli

GitHub API 的简单控制台封装

1.8.0-beta3 2023-02-10 01:58 UTC

This package is auto-updated.

Last update: 2024-09-04 12:07:20 UTC


README

The GitHubApiCli 组件是一个简单的控制台封装,用于 GitHub API,以允许抽象的命令行交互。

基于 knp-labs/github-api 构建。

用法

composer require devshop/github-api-cli
export GITHUB_TOKEN=aRealToken
bin/github whoami

--------------------------- ---------------------------------------------------------------- 
  Name                        Value                                                           
 --------------------------- ---------------------------------------------------------------- 
  login                       devshopbot                                                      
  id                          11931385                                                        
  node_id                     MDQ6VXNlcjExOTMxMzg1                                            
  avatar_url                  https://avatars2.githubusercontent.com/u/11931385?v=4           
  gravatar_id                                                                                 
  url                         https://api.github.com/users/devshopbot                         
  html_url                    https://github.com/devshopbot                                   
  followers_url               https://api.github.com/users/devshopbot/followers               
  following_url               https://api.github.com/users/devshopbot/following{/other_user}  
  gists_url                   https://api.github.com/users/devshopbot/gists{/gist_id}         
  starred_url                 https://api.github.com/users/devshopbot/starred{/owner}{/repo}  
  subscriptions_url           https://api.github.com/users/devshopbot/subscriptions           
  organizations_url           https://api.github.com/users/devshopbot/orgs                    
  repos_url                   https://api.github.com/users/devshopbot/repos                   
  events_url                  https://api.github.com/users/devshopbot/events{/privacy}        
  received_events_url         https://api.github.com/users/devshopbot/received_events         
  type                        User                                                            
  site_admin                                                                                  
  name                        devshopbot                                                      
  company                                                                                     
  blog                                                                                        
  location                                                                                    
  email                                                                                       
  hireable                                                                                    
  bio                                                                                         
  public_repos                2                                                               
  public_gists                0                                                               
  followers                   0                                                               
  following                   0                                                               
  created_at                  2015-04-13T20:05:05Z                                            
  updated_at                  2020-02-28T17:13:13Z                                            
  private_gists               0                                                               
  total_private_repos         0                                                               
  owned_private_repos         0                                                               
  disk_usage                  0                                                               
  collaborators               0                                                               
  two_factor_authentication                                                                   
 --------------------------- ---------------------------------------------------------------- 


命令

github api

直接传递到 `GitHub\Api\AbstractAPI 类。

 ./github api me
 --------------------------- ---------------------------------------------------------------- 
  Name                        Value                                                           
 --------------------------- ---------------------------------------------------------------- 
  login                       devshopbot                                                      
  id                          11931385                                                        
  node_id                     MDQ6VXNlcjExOTMxMzg1                                            
  avatar_url                  https://avatars2.githubusercontent.com/u/11931385?v=4       

目前只有 "show" 可以正常工作,但它应该能够成功返回任何对象。

/github api user show jonpugh
 --------------------- ------------------------------------------------------------- 
  Name                  Value                                                        
 --------------------- ------------------------------------------------------------- 
  login                 jonpugh                                                      
  id                    106420                                                       
  node_id               MDQ6VXNlcjEwNjQyMA==                                         
  avatar_url            https://avatars2.githubusercontent.com/u/106420?v=4          
  gravatar_id                                                                        
  url                   https://api.github.com/users/jonpugh                         
  html_url              https://github.com/jonpugh                                   
  followers_url         https://api.github.com/users/jonpugh/followers               

加载组织的详细信息

./github api organization show department-of-veterans-affairs
 --------------------------- ------------------------------------------------------------------------------------ 
  Name                        Value                                                                               
 --------------------------- ------------------------------------------------------------------------------------ 
  login                       department-of-veterans-affairs                                                      
  id                          5421563                                                                             
  node_id                     MDEyOk9yZ2FuaXphdGlvbjU0MjE1NjM=                                                    
  url                         https://api.github.com/orgs/department-of-veterans-affairs                          
  repos_url                   https://api.github.com/orgs/department-of-veterans-affairs/repos                    

显示仓库的详细信息

./github api repo show department-of-veterans-affairs va.gov-cms
 ------------------- ----------------------------------------------------------------------------------------------------------------- 
  Name                Value                                                                                                            
 ------------------- ----------------------------------------------------------------------------------------------------------------- 
  id                  154174777                                                                                                        
  node_id             MDEwOlJlcG9zaXRvcnkxNTQxNzQ3Nzc=                                                                                 
  name                va.gov-cms                                                                                                       
  full_name           department-of-veterans-affairs/va.gov-cms                                                                        
  private                                                                                                                              
  html_url            https://github.com/department-of-veterans-affairs/va.gov-cms                                                     

github deployment:start

创建一个新的部署,并将 ID 保存为 git 配置项。

bin/github deployment:start --environment=dev --description="Manual deployment triggered as an example."

然后使用 deployment:update 来更改状态。

github deployment:update

更新部署的状态。

bin/github deployment:update --state=in_progress --description="Building our thing..." --log_url=$OUR_BUILD_LOGS_URL

您可以使用 bash 操作符根据脚本的退出码设置不同的状态。

在命令后使用 && 来指定在成功时运行的命令。在命令后使用 || 来指定在失败时运行的命令。

deploy.sh \
   && bin/github deployment:update --state=success --description="This deployment update will only happen if deploy.sh returns exit code 0" \
   || ( bin/github deployment:update --state=failure --description="This deployment update will only happen if deploy.sh returns exit 1." && exit 1 )

请参阅 DevShop 构建测试作为示例 https://github.com/opendevshop/devshop/blob/09fbf10286994c378fa24cf6b9f91e9df33928dd/.github/workflows/build.yml#L110

如果您正在使用 CI 运行器,请确保在失败命令后执行 exit 1,以确保整体脚本的退出状态也是失败的。

SSL 问题

如果您遇到任何 SSL 错误,例如以下错误,您可以告诉 HTTPClient 库 Guzzle 跳过 SSL 验证。

60: SSL certificate problem: self signed certificate in certificate chain

所有使用 GitHub API 的 DevShop 组件都可以配置为跳过 SSL 证书验证。将以下环境变量设置为忽略 SSL 错误

export DEVSHOP_GITHUB_API_IGNORE_SSL=1

请参阅 YamlTasksConsoleCommand.phpGitHubApiCli.php 了解实现。

资源

致谢

$CREDITS