()
| 159 | } |
| 160 | |
| 161 | func githubLinkCmd() *cobra.Command { |
| 162 | var supplied GitHubPR |
| 163 | cmd := &cobra.Command{ |
| 164 | Use: "link [item-ref]", |
| 165 | Short: "Link the current branch's PR to a Pad item", |
| 166 | Long: `Link the current branch's GitHub pull request to a Pad item. |
| 167 | |
| 168 | If no item ref is provided, attempts to auto-detect from the branch name. |
| 169 | For example, branch "fix/TASK-5-oauth-bug" would auto-link to TASK-5.`, |
| 170 | Example: ` pad github link TASK-5 |
| 171 | pad github link fix-oauth-bug |
| 172 | pad github link # auto-detect from branch name |
| 173 | pad github link TASK-5 --pr-number 42 --pr-url https://github.com/acme/app/pull/42 --pr-state open`, |
| 174 | Args: cobra.MaximumNArgs(1), |
| 175 | RunE: func(cmd *cobra.Command, args []string) error { |
| 176 | client, _ := getClient() |
| 177 | ws := getWorkspace() |
| 178 | |
| 179 | bold := color.New(color.Bold) |
| 180 | dim := color.New(color.Faint) |
| 181 | green := color.New(color.FgGreen, color.Bold) |
| 182 | |
| 183 | // Supplied metadata (TASK-3611): an agent with no checkout or `gh` |
| 184 | // names the PR itself, and nothing is fetched from GitHub. The |
| 185 | // server validates the number and URL, as for a fetched PR. |
| 186 | var branch string |
| 187 | var pr *GitHubPR |
| 188 | // ANY supplied PR flag opts in: a lone --pr-title must |
| 189 | // not fall through to the branch and `gh`. |
| 190 | if anyFlagChanged(cmd, "pr-number", "pr-url", "pr-title", "pr-state", "pr-branch", "pr-repo") { |
| 191 | if supplied.Number <= 0 || supplied.URL == "" { |
| 192 | return fmt.Errorf("--pr-number and --pr-url are both required to link a PR you name") |
| 193 | } |
| 194 | if len(args) == 0 { |
| 195 | return fmt.Errorf("an item ref is required with --pr-number: pad github link TASK-5 --pr-number N --pr-url URL") |
| 196 | } |
| 197 | p := supplied |
| 198 | pr = &p |
| 199 | } else { |
| 200 | // Step 1: Get current branch |
| 201 | b, err := getCurrentBranch() |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | branch = b |
| 206 | if formatFlag != "json" { |
| 207 | dim.Printf("Branch: %s\n", branch) |
| 208 | } |
| 209 | |
| 210 | // Step 2: Fetch PR info |
| 211 | fetched, err := fetchGitHubPR() |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | pr = fetched |
| 216 | } |
| 217 | |
| 218 | text := formatFlag != "json" // JSON output carries only the item |
no test coverage detected