Skip to content

Commit

Permalink
Added new command line --print-flag to display the JQL behind an exis…
Browse files Browse the repository at this point in the history
…ting filter
  • Loading branch information
Kaian committed Nov 13, 2024
1 parent 8c42cc8 commit fe6db94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/jquery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ func main() {
return
}

// Handle the --print-filter flag
if flags.PrintFilter != 0 {
filter, err := client.GetFilter(flags.PrintFilter)
if err != nil {
log.Fatalf("Error retrieving filter: %v", err)
}
fmt.Printf("%s\n", filter.Jql)
return
}

// Build JQL query from flags
builder := jira.NewQueryBuilder()
jqlQuery := builder.BuildJQLQuery(flags, searchTerms)
Expand Down
1 change: 1 addition & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Flags struct {
ListProjects bool `long:"list-projects" description:"List all visible projects for current user"`
ListUsers bool `long:"list-users" description:"List all users in Jira"`
ListFilters bool `long:"list-filters" description:"List all saved filters in Jira"`
PrintFilter int `long:"print-filter" description:"Print the JQL query of a Jira filter by ID"`
Version bool `short:"v" long:"version" description:"Show the version"`
}

Expand Down
9 changes: 9 additions & 0 deletions internal/jira/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,12 @@ func (c *Client) GetAllFilters() (*FilterList, error) {

return NewFilterList(filters.Values, response.MaxResults, response.Total), nil
}

// GetFilter retrieves an existing Filter from Jira using the apiClient.
func (c *Client) GetFilter(id int) (*cloud.Filter, error) {
filter, _, err := c.apiClient.Filter.Get(context.Background(), id)
if err != nil {
return nil, err
}
return filter, nil
}

0 comments on commit fe6db94

Please sign in to comment.