MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / githubLinkCmd

Function githubLinkCmd

cmd/pad/cmd_github.go:161–280  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

159}
160
161func 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
168If no item ref is provided, attempts to auto-detect from the branch name.
169For 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

Callers 1

githubCmdFunction · 0.85

Calls 14

ItemRefFunction · 0.92
getClientFunction · 0.85
getWorkspaceFunction · 0.85
anyFlagChangedFunction · 0.85
getCurrentBranchFunction · 0.85
fetchGitHubPRFunction · 0.85
prStateColorFunction · 0.85
extractItemRefFromBranchFunction · 0.85
gitHubPRUpdateFunction · 0.85
verifyPRLinkedFunction · 0.85
outputJSONFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected