Skip to content

Commit

Permalink
comment test
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed Dec 30, 2023
1 parent e39d7d9 commit 277ce59
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 43 deletions.
11 changes: 8 additions & 3 deletions action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ runs:
inputs:
sarthi_server_url:
required: true
description: URL of the deployed sarthi server
description: 'URL of the deployed sarthi server'
compose_file:
required: false
description: Name of docker compose file in your project
description: 'Name of docker compose file in your project'
default: docker-compose.yml
sarthi_secret:
required: true
description: Secret text for authentication
fork_repo_url:
description: 'GitHub URL of Head Repo when a PR is created, default empty for push events'
default: ${{github.event.pull_request.head.repo.full_name}}
GITHUB_TOKEN:
description: 'Github token of the repository (automatically created by Github)'
default: ${{ github.token }}
45 changes: 19 additions & 26 deletions action/main.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
import os
import sys
import typing

from utils import deploy, comment_on_gh_pr

def main(args: typing.List[str]) -> None:
"""main function

Args:
args: STDIN arguments
"""
import os
def main() -> None:
event_name = os.environ.get("GITHUB_EVENT_NAME")
project_url = f"https://github.com/{os.environ.get('INPUT_FORK_REPO_URL') or os.environ.get('GITHUB_REPOSITORY')}.git"
branch_name = (
os.environ.get("GITHUB_HEAD_REF")
if event_name == "pull_request"
else os.environ.get("GITHUB_REF_NAME")
)
sarthi_secret = os.environ.get("INPUT_SARTHI_SECRET")
sarthi_server_url = os.environ.get("INPUT_SARTHI_SERVER_URL")

# Get all environment variables
env_vars = os.environ

# Print each environment variable
for key, value in env_vars.items():
print(f'{key}: {value}')

# GITHUB_REPOSITORY : octocat/Hello-World
project_name = os.environ.get("GITHUB_REPOSITORY").split("/")[1]
branch_name = os.environ.get("GITHUB_HEAD_REF")
username = os.environ.get("INPUT_REMOTE_USER")
password = os.environ.get("INPUT_REMOTE_PASSWORD")
host = os.environ.get("INPUT_REMOTE_HOST")
port = os.environ.get("INPUT_PORT") or 22
deployment_domain = os.environ.get("INPUT_DEPLOYMENT_DOMAIN")
github_token = os.environ.get("GITHUB_TOKEN")
sarthi_secret = os.environ.get('INPUT_SECRET')
# service_urls = deploy(
# project_git_url=project_url,
# branch=branch_name,
# sarthi_secret=sarthi_secret,
# sarthi_server_url=sarthi_server_url,
# )

comment_on_gh_pr("Hey boooyy")

if __name__ == "__main__":
main(sys.argv)
main()
2 changes: 1 addition & 1 deletion action/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests
pyjwt
pyjwt
40 changes: 27 additions & 13 deletions action/utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import requests
import os
import datetime
import json
import os
import jwt
import datetime

GITHUB_API_URL = os.environ.get('GITHUB_API_URL')
import requests


def comment_on_gh_pr(comment):
pass
GITHUB_API_URL = os.environ.get("GITHUB_API_URL")
GITHUB_TOKEN = os.environ.get('INPUT_GITHUB_TOKEN')

pr_number = os.environ.get("GITHUB_REF_NAME").split('/')[0]

url = f"{GITHUB_API_URL}/repos/{os.environ.get('GITHUB_REPOSITORY')}/issues/{pr_number}/comments"

headers = {
"Authorization": f"Bearer {GITHUB_TOKEN}",
"Accept": "application/vnd.github.v3+json",
}

data = {"body": comment}

response = requests.post(url, headers=headers, json=data)
response.raise_for_status()


def _generate_bearer_token(secret) -> str:
payload = {
'sub': 'sarthi',
'iat': datetime.datetime.utcnow(), # Issued at time
'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=1) # Expiration time
"sub": "sarthi",
"iat": datetime.datetime.utcnow(), # Issued at time
"exp": datetime.datetime.utcnow()
+ datetime.timedelta(minutes=1), # Expiration time
}

token = jwt.encode(payload, secret, algorithm='HS256')
token = jwt.encode(payload, secret, algorithm="HS256")
return f'Bearer {token.decode("utf-8")}'


Expand All @@ -28,9 +42,9 @@ def deploy(project_git_url, branch, sarthi_secret, sarthi_server_url):
"project_git_url": project_git_url,
"branch": branch,
}
response = requests.post(url=sarthi_server_url, headers=headers, data=json.dumps(body))
response = requests.post(
url=sarthi_server_url, headers=headers, data=json.dumps(body)
)
response.raise_for_status()
service_urls = response.json()
return service_urls


0 comments on commit 277ce59

Please sign in to comment.