feature: agrego implementacion de github remote api
This commit is contained in:
@@ -47,7 +47,8 @@ El comando solicitará 2 opciones:
|
|||||||
automáticamente. Por el momento, se soportan los siguientes remotos:
|
automáticamente. Por el momento, se soportan los siguientes remotos:
|
||||||
|
|
||||||
- [x] Bitbucket
|
- [x] Bitbucket
|
||||||
- [ ] Github: planeado
|
- [x] Github
|
||||||
|
- [x] Gitea
|
||||||
|
|
||||||
La configuración del remoto requiere tener un Access Token para poder crear los PRs automáticamente.
|
La configuración del remoto requiere tener un Access Token para poder crear los PRs automáticamente.
|
||||||
El mismo se puede crear desde el repositorio al que se quiere dar acceso: *"Repository settings" >
|
El mismo se puede crear desde el repositorio al que se quiere dar acceso: *"Repository settings" >
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import requests
|
||||||
from git_flow import GitFlowError
|
from git_flow import GitFlowError
|
||||||
from git_flow.remote.base import RemoteAPI
|
from git_flow.remote.base import RemoteAPI
|
||||||
|
|
||||||
|
|
||||||
class GithubRemoteAPI(RemoteAPI):
|
class GithubRemoteAPI(RemoteAPI):
|
||||||
API_ENDPOINT = "https://github.com"
|
API_ENDPOINT = "https://api.github.com/repos"
|
||||||
|
|
||||||
def create_pull_request(
|
def create_pull_request(
|
||||||
self,
|
self,
|
||||||
@@ -13,10 +14,33 @@ class GithubRemoteAPI(RemoteAPI):
|
|||||||
description: str | None = None,
|
description: str | None = None,
|
||||||
close_source_branch: bool = True
|
close_source_branch: bool = True
|
||||||
) -> str:
|
) -> str:
|
||||||
raise GitFlowError("not implemented yet!")
|
response = requests.post(
|
||||||
|
self.get_endpoint("/pulls"),
|
||||||
|
headers=self.get_headers(),
|
||||||
|
json={
|
||||||
|
"title": title,
|
||||||
|
"body": description,
|
||||||
|
"head": source,
|
||||||
|
"base": destination,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.ok:
|
||||||
|
return "PR creado exitosamente: " + response.json()["html_url"]
|
||||||
|
else:
|
||||||
|
raise GitFlowError("Ocurrió un error al crear el PR: " + response.text)
|
||||||
|
|
||||||
def create_tag(self, tag: str, commit: str) -> str:
|
def create_tag(self, tag: str, commit: str) -> str:
|
||||||
raise GitFlowError("not implemented yet!")
|
response = requests.post(
|
||||||
|
self.get_endpoint("/git/refs"),
|
||||||
|
headers=self.get_headers(),
|
||||||
|
json={"ref": f"refs/tags/{tag}", "sha": commit},
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.ok:
|
||||||
|
return "Tag creado exitosamente: " + tag
|
||||||
|
else:
|
||||||
|
raise GitFlowError("Ocurrió un error al crear el tag: " + response.text)
|
||||||
|
|
||||||
def get_endpoint(self, resource: str) -> str:
|
def get_endpoint(self, resource: str) -> str:
|
||||||
return GithubRemoteAPI.API_ENDPOINT
|
return f"{GithubRemoteAPI.API_ENDPOINT}/{self.repository}{resource}"
|
||||||
|
|||||||
Reference in New Issue
Block a user