Ben Chuanlong Du's Blog

It is never too late to learn.

Manipulate Branches of a Repository Using GitHub Rest APIs

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [1]:
from github_rest_api.github import Repository
In [2]:
repo = Repository(token="", owner="legendu-net", repo="docker-rust-cicd")
repo
Out[2]:
<github_rest_api.github.Repository at 0x7fd2c8d99090>
In [3]:
repo.list_branches()
Out[3]:
[{'name': 'dev',
  'commit': {'sha': '17bb5924aa766d7d5683efe81d69c5832ecb1674',
   'url': 'https://api.github.com/repos/legendu-net/docker-rust-cicd/commits/17bb5924aa766d7d5683efe81d69c5832ecb1674'},
  'protected': False},
 {'name': 'main',
  'commit': {'sha': 'dd7ac0d808d08cb03c5e5e5e5a6f597413f690e6',
   'url': 'https://api.github.com/repos/legendu-net/docker-rust-cicd/commits/dd7ac0d808d08cb03c5e5e5e5a6f597413f690e6'},
  'protected': True}]
In [4]:
repo.delete_ref?
Signature: repo.delete_ref(ref: str) -> None
Docstring:
Delete a reference from this repository.
:param ref: The reference to delete from this repository.
File:      ~/.local/lib/python3.10/site-packages/github_rest_api/github.py
Type:      method
In [5]:
repo.delete_branch?
Signature: repo.delete_branch(branch: str) -> None
Docstring:
Delete a branch from this repository.
:param branch: The branch to delete from this repository.
File:      ~/.local/lib/python3.10/site-packages/github_rest_api/github.py
Type:      method
In [ ]:
 

Comments