Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Conversation

@MorganEPatch
Copy link
Contributor

Depends on #11.

Move the configuration out of global variables and into a configuration object. Also begin moving other utility functions into lib/.

Copy link
Contributor

@squat squat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, @LyonesGamer! This is a much needed restructuring. Please re-arrange the remaining functions and then we can merge this.

// API.
func createComment(ghComment github.IssueComment, jIssue jira.Issue, ghClient github.Client, jClient jira.Client) error {
u, _, err := makeGHRequest(func() (interface{}, *github.Response, error) {
func createComment(config lib.Config, ghComment github.IssueComment, jIssue jira.Issue, ghClient github.Client, jClient jira.Client) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these functions that are not directly concerned with configuring and launching the command should be outside of this file and package. this function should be in lib.

// updateComment compares the body of a GitHub comment with the body (minus header)
// of the JIRA comment, and updates the JIRA comment if necessary.
func updateComment(ghComment github.IssueComment, jComment jira.Comment, jIssue jira.Issue, ghClient github.Client, jClient jira.Client) error {
func updateComment(config lib.Config, ghComment github.IssueComment, jComment jira.Comment, jIssue jira.Issue, ghClient github.Client, jClient jira.Client) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: all of these functions that are not directly concerned with configuring and launching the command should be outside of this file and package. this function should be in lib.

// matches each one to a comment in `existing`. If it finds a match, it calls
// updateComment; if it doesn't, it calls createComment.
func createComments(ghIssue github.Issue, jIssue jira.Issue, existing []jira.Comment, ghClient github.Client, jClient jira.Client) error {
func createComments(config lib.Config, ghIssue github.Issue, jIssue jira.Issue, existing []jira.Comment, ghClient github.Client, jClient jira.Client) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: all of these functions that are not directly concerned with configuring and launching the command should be outside of this file and package. this function should be in lib.

// createIssue generates a JIRA issue from the various fields on the given GitHub issue, then
// sends it to the JIRA API.
func createIssue(issue github.Issue, ghClient github.Client, jClient jira.Client) error {
func createIssue(config lib.Config, issue github.Issue, ghClient github.Client, jClient jira.Client) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: all of these functions that are not directly concerned with configuring and launching the command should be outside of this file and package. this function should be in lib.

// differ, the differing fields of the JIRA issue are updated to match the GitHub
// issue.
func updateIssue(ghIssue github.Issue, jIssue jira.Issue, ghClient github.Client, jClient jira.Client) error {
func updateIssue(config lib.Config, ghIssue github.Issue, jIssue jira.Issue, ghClient github.Client, jClient jira.Client) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: all of these functions that are not directly concerned with configuring and launching the command should be outside of this file and package. this function should be in lib.

// then matches each one. If a JIRA issue already exists for a given GitHub issue,
// it calls updateIssue; if no JIRA issue already exists, it calls createIssue.
func compareIssues(ghClient github.Client, jiraClient jira.Client) error {
func compareIssues(config lib.Config, ghClient github.Client, jiraClient jira.Client) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these functions that are not directly concerned with configuring and launching the command should be outside of this file and package. this function should be in lib.

cmd/root.go Outdated
// then makes an API request to confirm that the service is running and the auth token
// is valid
func getGitHubClient(token string) (*github.Client, error) {
func getGitHubClient(config lib.Config) (*github.Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be part of the the clients file. lib should know how to create a new github client given a config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been moved to the clients file. Some weird issue must have happened during rebasing or something...

cmd/root.go Outdated
//
// The validity of the client and its authentication are not checked here. One way
// to check them would be to call config.LoadJIRAConfig() after this function.
func getJIRAClient(config lib.Config) (*jira.Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be part of the the clients file. lib should know how to create a new jira client given a config.

@MorganEPatch
Copy link
Contributor Author

@squat Moving all of the functions into separate packages occurs in #14.

Copy link
Contributor

@squat squat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repo is starting to look much better. Just a few small comments.

lib/clients.go Outdated

// GetGitHubClient initializes a GitHub API client with an OAuth client for authentication,
// then makes an API request to confirm that the service is running and the auth token
// is valid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a period here.

cmd/root.go Outdated

// Execute provides a single function to run the root command and handle errors.
func Execute() {
// Create a temporary logger that we can use if an error occurs before the real one is instantiated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a period e here.

cmd/root.go Outdated
found := false
for _, jIssue := range jiraIssues {
id, _ := jIssue.Fields.Unknowns.Int(fmt.Sprintf("customfield_%s", ghIDFieldID))
id, _ := jIssue.Fields.Unknowns.Int(config.GetFieldKey(lib.GitHubID))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this suppressing an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's suppressing the error that the issue doesn't have the GitHub ID set; that can't happen since we filtered it by the GitHub ID. I'll add an error handler though, I suppose weird API errors are never unheard of.

lib/config.go Outdated
lastUpdate string
}

// Config is the root configuration object the application creates
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a period here too.

lib/config.go Outdated

// Config is the root configuration object the application creates
type Config struct {
// cmdFile is the file Viper is using for its configuration (default $HOME/.issue-sync.json)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make all of these comments full sentences please

lib/config.go Outdated

// NewConfig creates a new, immutable configuration object. This object
// holds the Viper configuration and the logger, and is validated. The
// JIRA configuration is not yet initialized
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

@MorganEPatch
Copy link
Contributor Author

@squat Fixed.

Create a new Config object which represents the current application
configuration. It stores both the viper configuration and computed
configuration values such as the custom field IDs. Also, move API
client related functions into a new lib file to make them accessible
to the whole application without circular imports.
@MorganEPatch MorganEPatch merged commit ff3af54 into coreos:master Aug 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants