// CompareIssues gets the list of GitHub issues updated since the `since` date,
// gets the list of JIRA issues which have GitHub ID custom fields in that list,
// 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.
CompareIssues gets the list of GitHub issues updated since the `since` date,
gets the list of JIRA issues which have GitHub ID custom fields in that list,
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.
// CompareIssues gets the list of GitHub issues updated since the ` since ` date // gets the list of JIRA issues which have GitHub ID custom fields in that list // 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(config cfg.Config, ghClient clients.GitHubClient, jiraClient clients.JIRAClient) error {
	log := config.GetLogger()
	log.Debug("Collecting issues")
	ghIssues, err := ghClient.ListIssues()
	if err != nil {
		return err
	}
	if len(ghIssues) == 0 {
		log.Info("There are no GitHub issues; exiting")
		return nil
	}
	ids := make([]int, len(ghIssues))
	for i, v := range ghIssues {
		ids[i] = v.GetID()
	}
	jiraIssues, err := jiraClient.ListIssues(ids)
	if err != nil {
		return err
	}
	log.Debug("Collected all JIRA issues")
	for _, ghIssue := range ghIssues {
		found := false
		for _, jIssue := range jiraIssues {
			id, _ := jIssue.Fields.Unknowns.Int(config.GetFieldKey(cfg.GitHubID))
			if int64(*ghIssue.ID) == id {
				found = true
				if err := UpdateIssue(config, ghIssue, jIssue, ghClient, jiraClient); err != nil {
					log.Errorf("Error updating issue %s. Error: %v", jIssue.Key, err)
				}
				break
			}
		}
		if !found {
			if err := CreateIssue(config, ghIssue, ghClient, jiraClient); err != nil {
				log.Errorf("Error creating issue for #%d. Error: %v", *ghIssue.Number, err)
			}
		}
	}
	return nil
}
func CompareIssues ( config cfg . Config , ghClient clients . GitHubClient , jiraClient clients . JIRAClient ) error { log := config . GetLogger ( ) log . Debug ( " " ) ghIssues , err := ghClient . ListIssues ( ) if err != nil { return err } if len ( ghIssues ) == 0 { log . Info ( " " ) return nil } ids := make ( [ ] int , len ( ghIssues ) ) for i , v := range ghIssues { ids [ i ] = v . GetID ( ) } jiraIssues , err := jiraClient . ListIssues ( ids ) if err != nil { return err } log . Debug ( " " ) for _ , ghIssue := range ghIssues { found := false for _ , jIssue := range jiraIssues { id , _ := jIssue . Fields . Unknowns . Int ( config . GetFieldKey ( cfg . GitHubID ) ) if int64 ( * ghIssue . ID ) == id { found = true if err := UpdateIssue ( config , ghIssue , jIssue , ghClient , jiraClient ) ; err != nil { log . Errorf ( " " , jIssue . Key , err ) } break } } if ! found { if err := CreateIssue ( config , ghIssue , ghClient , jiraClient ) ; err != nil { log . Errorf ( " " , * ghIssue . Number , err ) } } } return nil }
CompareIssues gets the list of GitHub issues updated since the `since` date,
gets the list of JIRA issues which have GitHub ID custom fields in that list,
then matches each one.
CompareIssues gets the list of GitHub issues updated since the ` since ` date gets the list of JIRA issues which have GitHub ID custom fields in that list then matches each one .