()
| 118 | } |
| 119 | |
| 120 | func githubLinkCmd() *cobra.Command { |
| 121 | return &cobra.Command{ |
| 122 | Use: "link [item-ref]", |
| 123 | Short: "Link the current branch's PR to a Pad item", |
| 124 | Long: `Link the current branch's GitHub pull request to a Pad item. |
| 125 | |
| 126 | If no item ref is provided, attempts to auto-detect from the branch name. |
| 127 | For example, branch "fix/TASK-5-oauth-bug" would auto-link to TASK-5. |
| 128 | |
| 129 | Examples: |
| 130 | pad github link TASK-5 |
| 131 | pad github link fix-oauth-bug |
| 132 | pad github link # auto-detect from branch name`, |
| 133 | Args: cobra.MaximumNArgs(1), |
| 134 | RunE: func(cmd *cobra.Command, args []string) error { |
| 135 | client, _ := getClient() |
| 136 | ws := getWorkspace() |
| 137 | |
| 138 | bold := color.New(color.Bold) |
| 139 | dim := color.New(color.Faint) |
| 140 | green := color.New(color.FgGreen, color.Bold) |
| 141 | |
| 142 | // Step 1: Get current branch |
| 143 | branch, err := getCurrentBranch() |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | dim.Printf("Branch: %s\n", branch) |
| 148 | |
| 149 | // Step 2: Fetch PR info |
| 150 | pr, err := fetchGitHubPR() |
| 151 | if err != nil { |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | stateColor := prStateColor(pr.State) |
| 156 | fmt.Printf("PR #%d %s %s\n", pr.Number, stateColor.Sprint(pr.State), dim.Sprint(pr.URL)) |
| 157 | fmt.Printf(" %s\n\n", bold.Sprint(pr.Title)) |
| 158 | |
| 159 | // Step 3: Determine target item |
| 160 | var itemRef string |
| 161 | if len(args) > 0 { |
| 162 | itemRef = args[0] |
| 163 | } else { |
| 164 | itemRef = extractItemRefFromBranch(branch) |
| 165 | if itemRef == "" { |
| 166 | return fmt.Errorf("could not detect item ref from branch %q. Specify one: pad github link TASK-5", branch) |
| 167 | } |
| 168 | dim.Printf("Auto-detected item ref: %s\n", itemRef) |
| 169 | } |
| 170 | |
| 171 | // Step 4: Resolve the item |
| 172 | item, err := client.GetItem(ws, itemRef) |
| 173 | if err != nil { |
| 174 | return fmt.Errorf("item %q not found: %w", itemRef, err) |
| 175 | } |
| 176 | |
| 177 | // Step 5: Update item fields with PR data |
no test coverage detected