github-commenter

授权协议 Apache-2.0 License
开发语言 Google Go
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 楚望
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

README Header

Cloud Posse

github-commenter Docker Status

Command line utility for creating GitHub comments on Commits, Pull Request Reviews, Pull Request Files, Issues and Pull Requests.

GitHub API supports these types of comments:

Since GitHub considers Pull Requests as Issues, Comments on Issues and Comments on Pull Requests use the same API.

The utility supports all these types of comments (commit, pr-review, pr-file, issue, pr).


This project is part of our comprehensive "SweetOps" approach towards DevOps.

It's 100% Open Source and licensed under the APACHE2.

Screenshots

GitHub PR Review Comment

Usage

NOTE: Create a GitHub token with repo:status and public_repo scopes.

NOTE: The utility accepts parameters as command-line arguments or as ENV variables (or any combination of command-line arguments and ENV vars).Command-line arguments take precedence over ENV vars.

Command-line argument ENV var Description
token GITHUB_TOKEN Github access token
owner GITHUB_OWNER Github repository owner (e.g. cloudposse)
repo GITHUB_REPO Github repository name (e.g. github-commenter)
type GITHUB_COMMENT_TYPE Comment type: commit, pr, issue, pr-review or pr-file
sha GITHUB_COMMIT_SHA Commit SHA. Required when type=commit or type=pr-file
number GITHUB_PR_ISSUE_NUMBER Pull Request or Issue number. Required for all comment types except for commit
file GITHUB_PR_FILE Pull Request File Name to comment on. For more info see create comment
position GITHUB_PR_FILE_POSITION Position in Pull Request File. For more info see create comment
template GITHUB_COMMENT_TEMPLATE Template to format comment (optional). Supports Go templates. E.g. My comment:<br/>{{.}}. Use either template or template_file
template_file GITHUB_COMMENT_TEMPLATE_FILE The path to a template file to format comment (optional). Supports Go templates. Use either template or template_file
format GITHUB_COMMENT_FORMAT Alias of template
format_file GITHUB_COMMENT_FORMAT_FILE Alias of template_file
comment GITHUB_COMMENT Comment text. If neither comment nor GITHUB_COMMENT provided, will read from stdin
delete-comment-regex GITHUB_DELETE_COMMENT_REGEX Regex to find previous comments to delete before creating the new comment. Supported for comment types commit, pr-file, issue and pr
baseURL GITHUB_BASE_URL Github Enterprise URL. E.g. https://github.example.com/api/v3
uploadURL GITHUB_UPLOAD_URL Github Enterprise Upload URL to pass to the Github client
insecure GITHUB_INSECURE Boolean to ignore SSL certificate check

NOTE: The utility accepts the text of the comment from the command-line argument comment, from the ENV variable GITHUB_COMMENT, or from the standard input.Command-line argument takes precedence over ENV var, and ENV var takes precedence over standard input.Accepting comments from stdin allows using Unix pipes to send the output from another program as the input to the tool:

cat comment.txt | github-commenter ...
terraform plan 2>&1 | github-commenter -format "Output from `terraform plan`<br/>```{{.}}```"

NOTE: The utility supports sprig functions in Go templates, allowing to use string replacement and Regular Expressions in the format argument.

See string functions for more details.

For example:

GITHUB_COMMENT_FORMAT="Helm diff:<br><br><pre>{{regexReplaceAllLiteral `\\n` . `<br>` }}<pre>"

Examples

The utility can be called directly or as a Docker container.

Build the Go program locally

go get

CGO_ENABLED=0 go build -v -o "./dist/bin/github-commenter" *.go

Run locally with ENV vars

run_locally_with_env_vars.sh

export GITHUB_TOKEN=XXXXXXXXXXXXXXXX
export GITHUB_OWNER=cloudposse
export GITHUB_REPO=github-commenter
export GITHUB_COMMENT_TYPE=pr
export GITHUB_PR_ISSUE_NUMBER=1
export GITHUB_COMMENT_FORMAT="My comment:<br/>{{.}}"
export GITHUB_COMMENT="+1 LGTM"

./dist/bin/github-commenter

Run locally with command-line arguments

run_locally_with_command_line_args.sh

./dist/bin/github-commenter \
        -token XXXXXXXXXXXXXXXX \
        -owner cloudposse \
        -repo github-commenter \
        -type pr \
        -number 1 \
        -format "My comment:<br/>{{.}}" \
        -comment "+1 LGTM"

Build the Docker image

NOTE: it will download all Go dependencies and then build the program inside the container (see Dockerfile)

docker build --tag github-commenter  --no-cache=true .

Run in a Docker container with ENV vars

run_docker_with_env_vars.sh

docker run -i --rm \
        -e GITHUB_TOKEN=XXXXXXXXXXXXXXXX \
        -e GITHUB_OWNER=cloudposse \
        -e GITHUB_REPO=github-commenter \
        -e GITHUB_COMMENT_TYPE=pr \
        -e GITHUB_PR_ISSUE_NUMBER=1 \
        -e GITHUB_COMMENT_FORMAT="My comment:<br/>{{.}}" \
        -e GITHUB_COMMENT="+1 LGTM" \
        github-commenter

Run with Docker

Run github-commenter in a Docker container with local ENV vars propagated into the container's environment.run_docker_with_local_env_vars.sh

export GITHUB_TOKEN=XXXXXXXXXXXXXXXX
export GITHUB_OWNER=cloudposse
export GITHUB_REPO=github-commenter
export GITHUB_COMMENT_TYPE=pr
export GITHUB_PR_ISSUE_NUMBER=1
export GITHUB_COMMENT_FORMAT="Helm diff:<br><br><pre>{{regexReplaceAllLiteral `\\n` . `<br>` }}<pre>"
export GITHUB_COMMENT="Helm diff comment"

docker run -i --rm \
        -e GITHUB_TOKEN \
        -e GITHUB_OWNER \
        -e GITHUB_REPO \
        -e GITHUB_COMMENT_TYPE \
        -e GITHUB_PR_ISSUE_NUMBER \
        -e GITHUB_COMMENT_FORMAT \
        -e GITHUB_COMMENT \
        github-commenter

Run with Docker using Env File

Run the github-commenter in a Docker container with ENV vars declared in a file.run_docker_with_env_vars_file.sh

docker run -i --rm --env-file ./example.env github-commenter

delete-comment-regex example 1

Delete all previous comments on Pull Request #2 that contain the string test1 in the body of the comments and create a new PR comment

./dist/bin/github-commenter \
        -token XXXXXXXXXXXXXXXX \
        -owner cloudposse \
        -repo github-commenter \
        -type pr \
        -number 2 \
        -format "{{.}}" \
        -delete-comment-regex "test1" \
        -comment "New Pull Request comment"

delete-comment-regex example 2

Delete all previous comments on Issue #1 that contain the string test2 at the end of the comment's body and create a new Issue comment

./dist/bin/github-commenter \
        -token XXXXXXXXXXXXXXXX \
        -owner cloudposse \
        -repo github-commenter \
        -type issue \
        -number 1 \
        -format "{{.}}" \
        -delete-comment-regex "test2$" \
        -comment "New Issue comment"

delete-comment-regex example 3

Delete all previous commit comments that contain the string test3 in the body and create a new commit comment

./dist/bin/github-commenter \
        -token XXXXXXXXXXXXXXXX \
        -owner cloudposse \
        -repo github-commenter \
        -type commit \
        -sha xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
        -format "{{.}}" \
        -delete-comment-regex "test3" \
        -comment "New commit comment"

delete-comment-regex example 4

Delete all previous comments on a Pull Request file doc.txt that contain the string test4 in the body of the comments and create a new comment on the file

./dist/bin/github-commenter \
        -token XXXXXXXXXXXXXXXX \
        -owner cloudposse \
        -repo github-commenter \
        -type pr-file \
        -sha xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
        -number 2 \
        -file doc.txt \
        -position 1 \
        -format "{{.}}" \
        -delete-comment-regex "test4" \
        -comment "New comment on the PR file"

Share the Love

Like this project? Please give it a ★ on our GitHub! (it helps us a lot)

Are you using this project or any of our other projects? Consider leaving a testimonial. =)

Related Projects

Check out these related projects.

  • github-status-updater - Command line utility for updating GitHub commit statuses and enabling required status checks for pull requests
  • slack-notifier - Command line utility to send messages with attachments to Slack channels via Incoming Webhooks

Help

Got a question? We got answers.

File a GitHub issue, send us an email or join our Slack Community.

README Commercial Support

DevOps Accelerator for Startups

We are a DevOps Accelerator. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.

Work directly with our team of DevOps experts via email, slack, and video conferencing.

We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet.

  • Reference Architecture. You'll get everything you need from the ground up built using 100% infrastructure as code.
  • Release Engineering. You'll have end-to-end CI/CD with unlimited staging environments.
  • Site Reliability Engineering. You'll have total visibility into your apps and microservices.
  • Security Baseline. You'll have built-in governance with accountability and audit logs for all changes.
  • GitOps. You'll be able to operate your infrastructure via Pull Requests.
  • Training. You'll receive hands-on training so your team can operate what we build.
  • Questions. You'll have a direct line of communication between our teams via a Shared Slack channel.
  • Troubleshooting. You'll get help to triage when things aren't working.
  • Code Reviews. You'll receive constructive feedback on Pull Requests.
  • Bug Fixes. We'll rapidly work with you to fix any bugs in our projects.

Slack Community

Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.

Discourse Forums

Participate in our Discourse Forums. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account.

Newsletter

Sign up for our newsletter that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.

Office Hours

Join us every Wednesday via Zoom for our weekly "Lunch & Learn" sessions. It's FREE for everyone!

zoom

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

If you are interested in being a contributor and want to get involved in developing this project or help out with our other projects, we would love to hear from you! Shoot us an email.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

Copyright

Copyright © 2017-2020 Cloud Posse, LLC

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Trademarks

All other trademarks referenced herein are the property of their respective owners.

About

This project is maintained and funded by Cloud Posse, LLC. Like it? Please let us know by leaving a testimonial!

Cloud Posse

We're a DevOps Professional Services company based in Los Angeles, CA. We ❤️ Open Source Software.

We offer paid support on all of our projects.

Check out our other projects, follow us on twitter, apply for a job, or hire us to help with your cloud strategy and implementation.

Contributors

Erik Osterman
Erik Osterman
Andriy Knysh
Andriy Knysh
Igor Rodionov
Igor Rodionov

README FooterBeacon

  • github是什么意思 by Alex Beregszaszi 通过亚历克斯·贝雷格萨斯(Alex Beregszaszi) 神秘的Github评论是什么意思? (What do cryptic Github comments mean?) Are you new to Github and/or contributing to open source projects? Have you see

  • The NERD Commenter  2011-05-18 21:05:37 分类: LINUX 作者:Marty Grenfell 脚本类型:公用(utility) 描述 从这里获取最新的开发版本 https://github.com/scrooloose/nerdcommenter 默认使用以下映射(同样有一个映射对应的菜单项) 以下多数映射只在普通或可视模式下使用。 |NERDComIns

 相关资料
  • 所以现在我们已经介绍了 GitHub 的大部分功能与工作流程,但是任意一个小组或项目都会去自定义,因为他们想要创造或扩展想要整合的服务。 对我们来说很幸运的是,GitHub 在许多方面都真的很方便 Hack。 在本节中我们将会介绍如何使用 GitHub 钩子系统与 API 接口,使 GitHub 按照我们的设想来工作。 钩子 GitHub 仓库管理中的钩子与服务区块是 GitHub 与外部系统交互

  • 你可以在 Github 上为项目创建远程仓库。创建公开的远程仓库是免费的,私有仓库要收费。 任务 在 Github 网站申请一个帐号。 https://github.com 配置帐号的 ssh-key。 https://github.com/settings/keys ssh-key 在 Github 个人帐户里配置使用了 ssh-key,以后你往你的 Github 远程仓库推送的时候就不需要输入

  • 代码仓库 我们在GitHub上进行Tengine项目的开发:https://github.com/alibaba/tengine。 可以用git检出最新的Tengine代码: 参与开发 我们非常欢迎也很鼓励您在Tengine的项目的GitHub上报告issue或者pull request。 如果您还不熟悉GitHub的Fork and Pull开发模式,您可以阅读GitHub的文档(https:/

  • 类属性 $allowSignup 是否在登录页显示注册,默认false

  •   推荐大家使用 https://gitee.com 速度更快,项目直接部署、Android 自动构建! 私有库永久免费,提供手机客户端,国内首个同时支持 Git 和 SVN 的代码托管平台) 如何一键导入 Github 仓库:https://blog.gitee.com/2018/06/05/github_to_gitee/ GitHub 可以托管各种 git 库,并提供一个 Web 界面,但与

  • 在本章中,我们将向您展示如何使用GitHub API对用户进行身份验证。 步骤1 - 启用GitHub身份验证 打开Firebase仪表板,然后单击侧面菜单中的Auth ,然后单击标签栏中的SIGN-IN-METHOD 。 您需要启用GitHub身份验证并复制Callback URL 。 您将在步骤2中使用此选项。您可以打开此选项卡,因为完成第2步后需要添加Client ID和Client Sec