feat(ingest/looker): add opt-in "View in Git" links to Explores

AV
1d ago
+770-20

Summary

Looker Views ingested by the lookml source already link to their LookML file in Git, but Explores have no way to get there: the Looker API's source_file is only the file name, and the looker source has no repository settings. This PR adds an opt-in option to the looker source that puts a View in Git button on each Explore, pointing at the LookML file that defines it.

source:
  type: looker
  config:
    extract_explore_git_links: true   # default: false

Before / after

Before: the Explore header only links to Looker.

Explore header before: only a View in Looker button

After (extract_explore_git_links: true): View in Git is the header button and opens the LookML file on GitHub; View in Looker is still there under View more.

Explore header after: View in Git button, with View in Looker under View more

How the link is built

  • File path: decoded from the Explore's lookml_link (/projects/<project>/files/<url-encoded path>?line=N), which carries the repo-relative path, including Explores defined in .view.lkml files.
  • Repository and branch: read from the Looker project API (git_remote_url, git_production_branch_name), once per project and cached, so the recipe needs no Git settings.
  • Remote parsing: only scheme://host/owner/repo and user@host:owner/repo remotes are accepted. Credentials and port are dropped, the host is lowercased, and the result goes through GitReference, the same helper the lookml source uses for Views (github.com and gitlab.com). A host is never guessed.
  • URL encoding: the file path and branch are URL-encoded, keeping /.

How the link is written

  • The link is an institutionalMemory entry labelled View in Git with showInAssetPreview: true, so it shows as a header button next to "View in Looker".
  • With a DataHub connection, the source reads the Explore's existing links once and manages every link labelled View in Git. It sends one PATCH keyed by url + label that removes non-current URLs and adds the current one. Nothing is written when the link is already correct, and links with other labels are never touched.
  • Without a DataHub connection, links are added only, and the report notes once that old links can't be cleaned up.
  • Two helpers are added to HasInstitutionalMemoryPatch: add_institutional_memory_by_url_and_label and remove_institutional_memory_by_url_and_label.

When a link can't be built

  • A project that can't be read, has no remote, or has a malformed or unsupported remote gets one warning per project. Its Explores get no new or updated link, and existing links are left unchanged. The remote itself is never echoed in the report.
  • Explores without a lookml_link (e.g. Looker's built-in system__activity) or defined in an imported project are skipped.

Testing

  • Unit tests in tests/unit/looker/test_looker_explore_git_links.py run the real source against a fake Looker client. They cover first add, unchanged run, URL change, remove-only, hand-made and other-label links, no DataHub connection, every project failure path, path and branch encoding, multiple projects, and remote parsing.
  • All Looker unit and integration tests pass, and existing goldens are unchanged with the option off.
  • Verified end to end against a local DataHub with a mocked Looker API. Links are replaced in place, other labels are kept, and the header button renders.
  • Verified read-only against a real Looker instance. Explores got correct GitHub links, including Explores defined in view files.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
  • Tests for the changes have been added/updated
  • Docs related to the changes have been added/updated (looker_post.md)
  • No breaking change (the option is off by default), so no entry in Breaking Changes

🤖 Generated with Claude Code


Summary by cubic

Adds an opt-in extract_explore_git_links option to the looker source that puts a View in Git button on each Explore, linking to the LookML file that defines it. The repository and production branch come from the Explore's Looker project, so the recipe needs no Git settings.

  • The file path comes from the Explore's lookml_link, anchored on its /projects/<project>/files/<path> layout; the repo and branch come from the Looker project API, cached per project.
  • Only github.com and gitlab.com remotes are supported, including user-less SCP remotes (github.com:org/repo.git) and alternate hosts (ssh.github.com, www.github.com, altssh.gitlab.com); malformed or unsupported remotes produce one warning per project and leave existing links unchanged.
  • With a DataHub connection each run replaces stale View in Git links in place; without one, links are add-only and the report notes it once.
  • Existing link reads run on worker threads, so they don't throttle parallel Explore fetches against a remote GMS; reads are also skipped once a project is known to have no usable remote, since nothing would be written for it.
  • A failed link read skips only that Explore's link: nothing is written for it and existing links are left unchanged, with a warning, and the rest of ingestion carries on.
  • Explores in an imported project get no link, and one that moves into an imported project or loses its LookML file keeps the link it already has; an Explore with no usable lookml_link is reported once per run.
  • Every link with that label on an Explore is managed by this option, so use another label for your own links.
  • Adds add_institutional_memory_by_url_and_label and remove_institutional_memory_by_url_and_label helpers to HasInstitutionalMemoryPatch.