niburg123
New Contributor III

You cannot use this as far as i know, but you can put a workaround in a notebook if you are calling code from your repo via a notebook:

repo_path = "/Repos/xyz_repo_path/xyz_repo_name"

repo_path_fs = "/Workspace" + repo_path

repo_branch = "main"

def checkRepoInfo():

  nb_context= json.loads(dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson())

  api_url = nb_context['extraContext']['api_url']

  api_token = nb_context['extraContext']['api_token']

  db_repo_data = requests.get(f"{api_url}/api/2.0/repos", headers = {"Authorization": f"Bearer {api_token}"}).json()

  for db_repo in db_repo_data["repos"]:

    db_repo_id = db_repo["id"]

    db_repo_path = db_repo["path"]

    db_repo_branch = db_repo["branch"]

    db_repo_head_commit = db_repo["head_commit_id"]

    if db_repo["path"] == repo_path:

      print ("Git commit info: ID: {} | Path: {} | Branch: {} | Commit: {}".format(db_repo_id, db_repo_path, db_repo_branch ,db_repo_head_commit))

      assert db_repo_branch == repo_branch

     

checkRepoInfo()

View solution in original post