getStatusField retrieves the Status field information for a project
(ctx context.Context, info projectURLInfo, verbose bool)
| 617 | |
| 618 | // getStatusField retrieves the Status field information for a project |
| 619 | func getStatusField(ctx context.Context, info projectURLInfo, verbose bool) (statusFieldInfo, error) { |
| 620 | var query string |
| 621 | var jqProjectID, jqFields string |
| 622 | |
| 623 | if info.scope == "orgs" { |
| 624 | query = fmt.Sprintf(`query { |
| 625 | organization(login: "%s") { |
| 626 | projectV2(number: %d) { |
| 627 | id |
| 628 | fields(first: 100) { |
| 629 | nodes { |
| 630 | ... on ProjectV2SingleSelectField { |
| 631 | id |
| 632 | name |
| 633 | options { name color description } |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | }`, escapeGraphQLString(info.ownerLogin), info.projectNumber) |
| 640 | jqProjectID = ".data.organization.projectV2.id" |
| 641 | jqFields = ".data.organization.projectV2.fields.nodes" |
| 642 | } else { |
| 643 | query = fmt.Sprintf(`query { |
| 644 | user(login: "%s") { |
| 645 | projectV2(number: %d) { |
| 646 | id |
| 647 | fields(first: 100) { |
| 648 | nodes { |
| 649 | ... on ProjectV2SingleSelectField { |
| 650 | id |
| 651 | name |
| 652 | options { name color description } |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | }`, escapeGraphQLString(info.ownerLogin), info.projectNumber) |
| 659 | jqProjectID = ".data.user.projectV2.id" |
| 660 | jqFields = ".data.user.projectV2.fields.nodes" |
| 661 | } |
| 662 | |
| 663 | // Get project ID |
| 664 | projectIDOutput, err := workflow.RunGH("Getting project info...", "api", "graphql", "-f", "query="+query, "--jq", jqProjectID) |
| 665 | if err != nil { |
| 666 | return statusFieldInfo{}, fmt.Errorf("failed to get project ID: %w", err) |
| 667 | } |
| 668 | projectID := strings.TrimSpace(string(projectIDOutput)) |
| 669 | |
| 670 | // Get fields |
| 671 | fieldsOutput, err := workflow.RunGH("Getting project fields...", "api", "graphql", "-f", "query="+query, "--jq", jqFields) |
| 672 | if err != nil { |
| 673 | return statusFieldInfo{}, fmt.Errorf("failed to get project fields: %w", err) |
| 674 | } |
| 675 | |
| 676 | // Parse fields to find Status field |
no test coverage detected