devshop / github-api-cli
GitHub API 的简单控制台封装
Requires
- php: ^7.1||^8.0
- consolidation/robo: ^2
- devshop/git-traits: @dev
- guzzlehttp/guzzle: ^6
- knplabs/github-api: ^3.9||^1.0
- php-http/guzzle6-adapter: 2.x-dev
- 2.x-dev
- 1.x-dev
- 1.8.x-dev
- 1.8.0-beta3
- 1.8.0-beta2
- 1.8.0-beta1
- 1.8.0-alpha1
- 1.7.x-dev
- 1.7.0-alpha4
- 1.7.0-alpha3
- 1.7.0-alpha2
- 1.7.0-alpha1
- 1.6.0-alpha4
- dev-bug/bitbucket-builds
- dev-bug/bitbucket/integration
- dev-bug/build-fast
- dev-bug/composer-broke
- dev-bug/composer-install-fails-preserve-paths
- dev-bug/deploy
- dev-bug/deploy-apis
- dev-bug/destroyed
- dev-bug/docker-logs-artifacts
- dev-bug/docker/actions
- dev-bug/docker/hub
- dev-bug/everything
- dev-bug/failing-again
- dev-bug/fucked-containers
- dev-bug/full-stack-stuff
- dev-bug/github/actions
- dev-bug/last-passing-commit
- dev-bug/little-things
- dev-bug/local/docker-command
- dev-bug/no-drush
- dev-bug/provision-files
- dev-bug/queues
- dev-bug/remote-hosts
- dev-bug/reset
- dev-bug/sync
- dev-bug/tasks
- dev-bug/ubuntu-scripts
- dev-bug/unpreserved-paths
- dev-bug/updated-containers
- dev-bug/upgrade
- dev-bug/verify
- dev-bug/verify-fail-after-install
- dev-bugs/beta-blockers
- dev-bugs/contrib
- dev-bugs/various
- dev-component/devshop-behat-extension
- dev-dev/github/fixes
- dev-dev/stuff
- dev-feature/ansible-tweaks
- dev-feature/ansible/faster
- dev-feature/bitbucket-fixes
- dev-feature/commands
- dev-feature/development/lando
- dev-feature/devshop-control-in-root
- dev-feature/devshop-platform
- dev-feature/drupal-10
- dev-feature/hosting/default_hosting_settings
- dev-feature/hosting_docker
- dev-feature/linuxserver
- dev-feature/megamerge
- dev-feature/minor-ansible-improvements
- dev-feature/no-platforms
- dev-feature/php-81-default
- dev-feature/php-intl
- dev-feature/php/8.1-default
- dev-feature/platform-user
- dev-feature/reinstall
- dev-feature/release-docs
- dev-feature/remote-host-container
- dev-feature/site-audit
- dev-feature/ubuntu22
- dev-release-1.8.0-beta1
- dev-release-1.8.0-beta2
- dev-tests/docker/from-devshop-server
- dev-tests/failing-install
- dev-updates/2023-10
- dev-bug/github/settings-ui
- dev-bug/ansible/detect-site
- dev-bug/docker/no-buildtime-tag
- dev-bug/hosting-queue-runner-commands
- dev-dev/install/platforms
- dev-feature/composer/git-traits
- dev-feature/docker/hub-publish
- dev-feature/php/8.1
- dev-ops/ansible/default-project-vars
- dev-php81
- dev-bug/docker/build-again
- dev-bug/docker/removed-too-much
- dev-bug/scripts/fix-path
- dev-bug/sites/git-reset
- dev-feature/components/php-8
- dev-feature/docker/build-run
- dev-feature/docker/fix-it-all
- dev-feature/os/ubuntu20
- dev-feature/os/ubuntu2004
- dev-feature/php-8
- dev-feature/php/8
- dev-feature/php/8.0
- dev-feature/robo/cleanup
- dev-feature/php80
- dev-bug/ch112/release-fixes
- dev-bug/ch118/provision-release
- dev-bug/ch118/test-fails
- dev-bug/ch118/uid-reset
- dev-bug/ch122/test-devshop-control
- dev-bug/ch177/detect-hostname
- dev-bug/ch185/composer-1
- dev-bug/ch185/composer-2
- dev-bug/ch460/bad-1.x-builds
- dev-bug/ch460/scheduled-build-branch
- dev-bug/ch472/composer-devshop-control
- dev-bug/ch477/composer-tests
- dev-bug/ch477/lost-control
- dev-bug/ch479/simplify-ansible-inventory-generation
- dev-bug/ch504/1x-ci-fail
- dev-bug/ch505/ansible-role-vars
- dev-bug/ch586/main-branch-tests
- dev-bug/ch587/install-sh-forks
- dev-bug/chXYZ/yaml-tasks-bugs
- dev-bug/components-ci-fail
- dev-bug/composer-ansible-fail
- dev-bug/composer-common-installable
- dev-bug/composer-fail
- dev-bug/docker-compose-up
- dev-bug/gh385/deploy
- dev-bug/gh642/disabled-sites
- dev-bug/gh656/protect-site
- dev-bug/git-split/composer-plugin-api-version
- dev-bug/hosting-queue-stop
- dev-bug/install-builder
- dev-bug/pr655/tests-failing
- dev-bug/tests-and-local
- dev-component/composer/deploy
- dev-component/devmaster/task-line-numbers
- dev-dependabot/add-v2-config-file
- dev-dev/environment/classes
- dev-dev/support/fixes
- dev-dev/ux/task-site-urls
- dev-dev/ux/tasks
- dev-feature/ch115/hugo-site
- dev-feature/ch121/links-to-domains
- dev-feature/ch139/ansible-cloud
- dev-feature/ch139/repos
- dev-feature/ch256/devshop-developers
- dev-feature/ch475/better-install-sh
- dev-feature/ch534/github-actions-checkout
- dev-feature/ch584/better-dx
- dev-feature/ch86/deploy
- dev-feature/ch86/deploy-component
- dev-feature/ch90/readme
- dev-feature/gh644/devshop-control-codebase
- dev-feature/gh644/path-devmaster-repo
- dev-feature/git-remote-monitor
- dev-feature/php-versions
- dev-feature/shape-up
- dev-feature/ubuntu20
- dev-ops/ansible/update
- dev-pr/655
- dev-release-1.7.0
- dev-testing/php74
- dev-tests/control/pseudo-repo
- dev-ux/create/redirect
- dev-feature/ch81/composer-devshop
- dev-integration
- dev-component/composer/devmaster
- dev-bug/ch101/devshop-test-volumes
- dev-bug/ch17/test-assets-folder
- dev-bug/ch20/ansible-lint
- dev-bug/ch35/tests-passing
- dev-bug/ch36/little-bugs
- dev-ci/install/devshop-tech
- dev-ci/makefiles/ci-makefile
- dev-component/composer/set-path
- dev-components
- dev-dev/devshop/docker-tools
- dev-feature/ch37/dev-environment
- dev-feature/ch87/rapid-tests
- dev-feature/ch87/rapid-tests-2
- dev-feature/ch89/core-values
- dev-feature/test-composer-template
- dev-install/install-sh/ansible-pip
- dev-ops/docker/dockerfiles
- dev-ops/os/centos8
- dev-pull/589
- dev-component/docs
- dev-composer/node/suggests
- dev-install/get.devshop.tech
- dev-ci/github/actions-branches
- dev-ci/github/actions-fixes
- dev-component/github-api-cli/ssl-ignore
- dev-dependabot/composer/composer/composer-1.10.4
- dev-dependabot/composer/composer/composer-1.10.5
- dev-develop
- dev-component/github-api-cli/deployments
- dev-component/common
- dev-component/github-cli
- dev-dependabot/composer/drush/drush-10.2.2
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.php 和 GitHubApiCli.php 了解实现。
资源
致谢
$CREDITS