Skip to content

fix: resolve CWE-665 — make xurl importable as a Go library#1

Merged
drQedwards merged 4 commits intomainfrom
copilot/fix-go-import-issue
Mar 3, 2026
Merged

fix: resolve CWE-665 — make xurl importable as a Go library#1
drQedwards merged 4 commits intomainfrom
copilot/fix-go-import-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 2, 2026

  • Create xurl.go at root as package xurl with exported library API (NewRootCommand, CreateRootCommand, Execute)
  • Create cmd/xurl/main.go as CLI entry point (package main)
  • Remove old main.go (replaced by xurl.go + cmd/xurl/main.go)
  • Update Makefile build/install targets to use ./cmd/xurl
  • Update README.md with correct install path and library usage docs
  • Fix auth/auth.go: WithAppName always overwrites credentials; add AppName() getter; use ForApp variants throughout
  • Fix api/client.go: use ForApp variants so active app is respected
  • Add tests for multi-app auth behavior
  • Fix .gitignore to use root-anchored /xurl pattern (avoids ignoring cmd/xurl/)
  • Verify build and all tests pass
  • Fix import grouping in api/client.go and api/media.go (stdlib / third-party separation)
  • Fix README replace directive to use full module path instead of short xurl path
  • Run code review and CodeQL checks (0 security alerts)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 2, 2026 23:58
… Go library

- Create xurl.go (package xurl) with exported library API
- Move CLI entry point to cmd/xurl/main.go
- Fix WithAppName to always overwrite credentials
- Add AppName() getter for multi-app token resolution
- Use ForApp variants in auth and API client
- Update Makefile and README for new package structure
- Add comprehensive multi-app tests

Co-authored-by: drQedwards <213266729+drQedwards@users.noreply.github.com>
…l/main.go

Co-authored-by: drQedwards <213266729+drQedwards@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix import initialization issue for GoLang project fix: resolve CWE-665 — make xurl importable as a Go library Mar 3, 2026
@drQedwards drQedwards marked this pull request as ready for review March 3, 2026 00:28
@drQedwards drQedwards requested review from Copilot and drQedwards March 3, 2026 00:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures the repository so it can be imported as a Go library (github.com/xdevplatform/xurl) while keeping the CLI as a separate cmd/xurl entrypoint, and it fixes multi-app authentication behavior so token/credential operations respect the active app context.

Changes:

  • Converted module root into package xurl and added NewRootCommand, CreateRootCommand, and Execute for library consumers.
  • Moved CLI entrypoint to cmd/xurl/main.go and updated build/install instructions (Makefile, README, .gitignore).
  • Updated auth + API client logic to use app-scoped token store operations; added multi-app tests.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
xurl.go Adds importable library API for constructing/executing the root Cobra command.
cmd/xurl/main.go New CLI entrypoint under cmd/xurl.
auth/auth.go Makes credential/token operations app-aware; adds AppName() getter.
auth/auth_test.go Adds multi-app auth tests (credential overwrite, token isolation, etc.).
api/client.go Updates auto-auth cascade to use app-scoped token lookups.
api/client_test.go Adds test ensuring active app’s bearer token is used.
api/media.go Import formatting adjustment (needs gofmt grouping).
README.md Updates install path + documents library usage (one section is currently misleading).
Makefile Builds/installs from ./cmd/xurl.
.gitignore Stops ignoring cmd/xurl by narrowing ignore rule to /xurl.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

README.md Outdated
Comment on lines +47 to +52
If your consuming project uses a local replace for this repo and requires the short path, `import "xurl"` also works with:

```go
require xurl v0.0.0

replace xurl => ../xurl
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README suggests import "xurl" will work with require xurl v0.0.0 + replace xurl => ../xurl, but this repo’s packages import each other via the full module path (github.com/xdevplatform/xurl/...). Using the short module path will break those internal imports unless they’re rewritten too. Consider removing the import "xurl" guidance or instead documenting replace github.com/xdevplatform/xurl => ../xurl (while keeping import "github.com/xdevplatform/xurl").

Suggested change
If your consuming project uses a local replace for this repo and requires the short path, `import "xurl"` also works with:
```go
require xurl v0.0.0
replace xurl => ../xurl
If your consuming project uses a local checkout of this repo, you can use a `replace` directive in your `go.mod` while still importing by the full module path:
```go
require github.com/xdevplatform/xurl v0.0.0
replace github.com/xdevplatform/xurl => ../xurl

Copilot uses AI. Check for mistakes.
Comment on lines 11 to 21
"time"

"bufio"
"mime/multipart"
"os"
"path/filepath"
"github.com/xdevplatform/xurl/auth"
"github.com/xdevplatform/xurl/config"
xurlErrors "github.com/xdevplatform/xurl/errors"
"github.com/xdevplatform/xurl/version"
"mime/multipart"
"os"
"path/filepath"
)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import block isn’t gofmt-compliant: stdlib imports (bufio, mime/multipart, os, path/filepath, etc.) are interleaved with module imports and not separated into groups. Please run gofmt (or reorder into stdlib / third-party / local groups) to keep consistent formatting and avoid noisy diffs.

Copilot uses AI. Check for mistakes.
@drQedwards
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

… directive

- README.md: Replace incorrect `import "xurl"` guidance with proper
  `replace github.com/xdevplatform/xurl => ../xurl` directive
- api/client.go: Reorder imports into stdlib / third-party groups
- api/media.go: Reorder imports into stdlib / third-party groups

Co-authored-by: drQedwards <213266729+drQedwards@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Mar 3, 2026

@copilot apply changes based on the comments in this thread

Applied all three review comments in ad5449d:

  1. README.md: Replaced the incorrect import "xurl" / require xurl guidance with proper replace github.com/xdevplatform/xurl => ../xurl using the full module path.
  2. api/client.go: Reordered imports into stdlib / third-party groups (gofmt-compliant).
  3. api/media.go: Moved github.com/xdevplatform/xurl/utils into a separate import group after stdlib imports.

@drQedwards drQedwards merged commit 7867238 into main Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants