Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: (DSP-2004) Apply good practice to code #6

Merged
merged 8 commits into from
Aug 27, 2024
Merged
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ jobs:
--from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
--to ${{ github.event.pull_request.head.sha }}
--verbose

- name: 🔎 Validate PR title with commitlint
run: echo "${{ github.event.pull_request.title }}" | npx commitlint
71 changes: 0 additions & 71 deletions .release-it.json

This file was deleted.

10 changes: 6 additions & 4 deletions cmd/create_comment.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package cmd

import (
commentGithub "github.com/gbh-tech/github-pr-commenter/src"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var createCommentPrCmd = &cobra.Command{
Use: "create",
Aliases: []string{"new"},
Short: "Create new comment on PR",
Example: "atlas comment create [flags]",
Example: "commenter create [flags]",
Run: func(cmd *cobra.Command, args []string) {
pull, _ := cmd.Flags().GetInt("pull")
repo, _ := cmd.Flags().GetString("repo")
org, _ := cmd.Flags().GetString("org")
content, _ := cmd.Flags().GetString("content")
filePath, _ := cmd.Flags().GetString("filePath")

commentGithub.CreateComment(pull, org, repo, content, filePath)
_, err := GithubClient.CreateComment(pull, org, repo, content, filePath)
if err != nil {
log.Fatalf("Error: %v\n", err)
}
},
}

Expand Down
11 changes: 8 additions & 3 deletions cmd/get_comment.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package cmd

import (
commentGithub "github.com/gbh-tech/github-pr-commenter/src"
"fmt"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var getCommentPrCmd = &cobra.Command{
Use: "get",
Short: "Get message ID based on text",
Example: "atlas comment get [flags]",
Example: "commenter get [flags]",
Run: func(cmd *cobra.Command, args []string) {
pull, _ := cmd.Flags().GetInt("pull")
repo, _ := cmd.Flags().GetString("repo")
org, _ := cmd.Flags().GetString("org")
content, _ := cmd.Flags().GetString("content")
filePath, _ := cmd.Flags().GetString("filePath")

commentGithub.GetUserComments(pull, org, repo, content, filePath)
commentID, err := GithubClient.GetUserComments(pull, org, repo, content, filePath)
if err != nil {
log.Fatalf("Error: %v\n", err)
}
fmt.Printf("%v", commentID)
},
}

Expand Down
11 changes: 11 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ package cmd
import (
"os"

comments "github.com/gbh-tech/github-pr-commenter/src/comments"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var GithubClient comments.GithubClient

var RootCmd = &cobra.Command{
Use: "commenter",
Short: "A CLI to perform operation on GitHub PR issues.",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
token := os.Getenv("GITHUB_TOKEN")
err := comments.NewClient(token, &GithubClient)
if err != nil {
log.Fatalf("Error initializing GitHub client: %v", err)
}
},
}

func init() {
Expand Down
10 changes: 6 additions & 4 deletions cmd/update_comment.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package cmd

import (
commentGithub "github.com/gbh-tech/github-pr-commenter/src"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var updateCommentPrCmd = &cobra.Command{
Use: "update",
Short: "Update comment on PR",
Example: "atlas comment update [flags]",
Example: "commenter update [flags]",
Run: func(cmd *cobra.Command, args []string) {
repo, _ := cmd.Flags().GetString("repo")
org, _ := cmd.Flags().GetString("org")
content, _ := cmd.Flags().GetString("content")
filePath, _ := cmd.Flags().GetString("filePath")
commentID, _ := cmd.Flags().GetInt64("commentID")

commentGithub.UpdateComment(commentID, org, repo, content, filePath)
_, err := GithubClient.UpdateComment(commentID, org, repo, content, filePath)
if err != nil {
log.Fatalf("Error: %v\n", err)
}
javiercm1410 marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down
1 change: 0 additions & 1 deletion commitlint.config.js

This file was deleted.

77 changes: 77 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,82 @@
"commitlint": "^19.2.1",
"husky": "^9.0.11",
"release-it": "^17.3.0"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
],
"defaultIgnores": true
},
"release-it": {
"github": {
"release": false,
"releaseName": "v${version}"
},
"git": {
"commitMessage": "chore: release v${version}",
"tagMatch": "v[0-9]*\\.[0-9]*\\.[0-9]*",
"tagName": "v${version}",
"getLatestTagFromAllRefs": true,
"tagExclude": "*[-]*",
"push": true,
"release": true,
"pushArgs": ["--no-verify", "--follow-tags", "--force"],
"commitArgs": ["--no-verify"]
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Miscellaneous"
},
{
"type": "docs",
"section": "Miscellaneous"
},
{
"type": "style",
"section": "Miscellaneous"
},
{
"type": "refactor",
"section": "Miscellaneous"
},
{
"type": "perf",
"section": "Miscellaneous"
},
{
"type": "test",
"section": "Miscellaneous"
},
{
"type": "build",
"section": "Miscellaneous"
},
{
"type": "revert",
"section": "Miscellaneous"
},
{
"type": "ci",
"section": "Miscellaneous"
}
]
},
"infile": "CHANGELOG.md"
}
}
}
}
88 changes: 0 additions & 88 deletions src/comments.go

This file was deleted.

Loading
Loading