Skip to content

Commit

Permalink
Merge pull request #8 from ThelonKarrde/feature/gitlab_support
Browse files Browse the repository at this point in the history
Feature/gitlab support
  • Loading branch information
ThelonKarrde authored Feb 28, 2021
2 parents 7daeee6 + afdebe4 commit ff17a1d
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 136 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
# vendor/

#Ignore IntelliJ project folder
.idea
.idea

#Ignore binary builds
main
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - tbd
### Added
- GitLab support

## [0.1.1] - 2021-02-19
### Changed
- Golang version 1.15 -> 1.16
Expand Down
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,62 @@
A tool to sent comments to Issues or Pull Requests in Github from CI tools.

---
### Platforms

| Supported platforms | Fully supported | In development |
|---------------------|-----------------|----------------|
| Github || |
| GitLab || |
| BitBucket | ||

### Usage

Required environment variables:
* `GITHUB_COMMENT_USER` - User from which name will be sent comments to Github
* `GITHUB_COMMENT_TOKEN` - Personal Token for comment user. [Github doc](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
* `API_USER` - User from which name will be sent comments.
* `API_TOKEN` - Personal Token for comment user.

Available parameters:
```
usage: CommentCI [-h|--help] -o|--github-owner "<value>" -r|--github-repository
"<value>" [-s|--single-comment "<value>"] [-c|--codify]
[-f|--file "<value>" [-f|--file "<value>" ...]]
[-l|--file-comment "<value>" [-l|--file-comment "<value>"
...]] -i|--issue-number <integer> [-m|--multi-comment]
usage: CommentCI [-h|--help] -o|--owner "<value>" -r|--repository "<value>"
[-s|--single-comment "<value>"] [-c|--codify] [-f|--file
"<value>" [-f|--file "<value>" ...]] [-l|--file-comment
"<value>" [-l|--file-comment "<value>" ...]] -i|--issue-number
<integer> [-m|--multi-comment] -p|--platform (github|gitlab)
[-g|--target-type (issue|merge-request)]
Sent a comment to GitHub PR or Issue from your CI
Arguments:
-h --help Print help information
-o --github-owner Owner of the repository. User/Organisations.
-r --github-repository Name of the github repository.
-s --single-comment Single comment string to sent to GitHub.
-c --codify Put comments to the Markdown code block.
-f --file By repeating this flag you can specify multiple
files which content will be sent to comment.
-l --file-comment By repeating this flag you can specify comments for
provided files in according order.
-i --issue-number Number(id) of the Issue/PR to sent a comment.
-m --multi-comment Put each file into a separate comment in GitHub..
Default: false
-h --help Print help information
-o --owner Owner of the repository. User/Organisations.
-r --repository Name of the repository.
-s --single-comment Single comment string to sent to GitHub.
-c --codify Put format to the Markdown code block.
-f --file By repeating this flag you can specify multiple files
which content will be sent to comment.
-l --file-comment By repeating this flag you can specify format for
provided files in according order.
-i --issue-number Number(id) of the Issue/PR to sent a comment.
-m --multi-comment Put each file into a separate comment in GitHub..
Default: false
-p --platform Select platform where to send format
-g --target-type Select type of comment target (GitLab only)
```

Usage examples:
<br></br>
Single comment:
```
GITHUB_COMMENT_USER=user GITHUB_COMMENT_TOKEN=xxx commentci -o repo_owner -r repo_name -i 2 -s "Single comment"
API_USER=user API_TOKEN=xxx commentci -g github -o repo_owner -r repo_name -i 2 -s "Single comment"
```
<br></br>
Single file with a comment:
```
GITHUB_COMMENT_USER=user GITHUB_COMMENT_TOKEN=xxx commentci -o repo_owner -r repo_name -i 2 -c -l "Comment to example file" -f ./example.txt
API_USER=user API_TOKEN=xxx commentci -g github -o repo_owner -r repo_name -i 2 -c -l "Comment to example file" -f ./example.txt
```
<br></br>
Multiple files with comments:
```
GITHUB_COMMENT_USER=user GITHUB_COMMENT_TOKEN=xxx commentci -o repo_owner -r repo_name -i 2 -c -l "Comment to example file 1" -f ./example_1.txt -l "Comment to example file 2" -f ./example_2.txt
API_USER=user API_TOKEN=xxx commentci -g github -o repo_owner -r repo_name -i 2 -c -l "Comment to example file 1" -f ./example_1.txt -l "Comment to example file 2" -f ./example_2.txt
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.2.0
44 changes: 23 additions & 21 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package main

import (
cmt "github.com/ThelonKarrde/CommentCI/internal/comments"
"github.com/ThelonKarrde/CommentCI/internal/config"
"github.com/ThelonKarrde/CommentCI/internal/format"
ghi "github.com/ThelonKarrde/CommentCI/internal/github"
glb "github.com/ThelonKarrde/CommentCI/internal/gitlab"
"github.com/ThelonKarrde/CommentCI/internal/utils"
"log"
)

func main() {
data := config.ReadConfig()
if data.CommentText != "" {
if len(data.FileList) != 0 {
log.Println("Warning! Both single-comment and file-comment args are specified! Priority over single comment flag.")
}
comment := cmt.MakeComment(data.CommentText, "", data.CodeStyleMode)
ghi.CommentIssue(&comment, data.GitHubCommentToken, data.GitHubRepoOwner, data.GitHubRepoName, data.IssueNumber)
cfg := config.ReadConfig()
var comments []string
if cfg.CommentText != "" {
comments = append(comments, format.Comment(cfg.CommentText, "", cfg.CodeStyleMode))
} else {
if data.MultiCommentMode == false {
if data.FileList != nil {
comment := cmt.MakeSingleComment(utils.ConvertFilesToStrings(data.FileList), data.CommentFiles, data.CodeStyleMode)
ghi.CommentIssue(&comment, data.GitHubCommentToken, data.GitHubRepoOwner, data.GitHubRepoName, data.IssueNumber)
if cfg.MultiCommentMode {
for i, p := range cfg.FileList {
cmt := ""
if i < len(cfg.CommentFiles) {
cmt = cfg.CommentFiles[i]
}
comments = append(comments, format.Comment(utils.ReadFileToString(p), cmt, cfg.CodeStyleMode))
}
} else {
if len(cfg.FileList) > 0 {
comments = append(comments, format.SingleComment(utils.ConvertFilesToStrings(cfg.FileList), cfg.CommentFiles, cfg.CodeStyleMode))
} else {
log.Fatalf("No files specified!")
}
}
}
for _, c := range comments {
if cfg.Platform == "github" {
ghi.Comment(&c, cfg.ApiToken, cfg.RepoOwner, cfg.RepoName, cfg.IssueNumber)
} else {
for i, p := range data.FileList {
var comment string
if i >= len(data.CommentFiles) {
comment = cmt.MakeComment(utils.ReadFileToString(p), "", data.CodeStyleMode)
} else {
comment = cmt.MakeComment(utils.ReadFileToString(p), data.CommentFiles[i], data.CodeStyleMode)
}
ghi.CommentIssue(&comment, data.GitHubCommentToken, data.GitHubRepoOwner, data.GitHubRepoName, data.IssueNumber)
}
glb.Comment(cfg.TargetType, &c, cfg.ApiToken, cfg.RepoOwner, cfg.RepoName, cfg.IssueNumber)
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ go 1.16
require (
github.com/akamensky/argparse v1.2.2
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/xanzy/go-gitlab v0.44.0
golang.org/x/oauth2 v0.0.0-20210201163806-010130855d6c
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -99,6 +100,11 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.4 h1:BbgctKO892xEyOXnGiaAwIoSq1QZ/SS4AhjoAh9DnfY=
github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand All @@ -112,7 +118,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/xanzy/go-gitlab v0.44.0 h1:cEiGhqu7EpFGuei2a2etAwB+x6403E5CvpLn35y+GPs=
github.com/xanzy/go-gitlab v0.44.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -158,6 +168,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -184,6 +195,7 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -230,6 +242,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -292,6 +305,7 @@ google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0M
google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
Expand Down
34 changes: 0 additions & 34 deletions internal/comments/comments.go

This file was deleted.

Loading

0 comments on commit ff17a1d

Please sign in to comment.