diff --git a/.github/workflows/email-test2.yaml b/.github/workflows/email-test2.yaml index eaec5c8..0e90c1b 100644 --- a/.github/workflows/email-test2.yaml +++ b/.github/workflows/email-test2.yaml @@ -1,5 +1,5 @@ -on: [ pull_request, push ] +on: [ pull_request ] permissions: checks: write @@ -10,8 +10,29 @@ jobs: runs-on: [ self-hosted ] steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: foobar env: GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo $GITHUB_CONTEXT - + run: echo $GITHUB_CONTEXT | jq + - run: git log --pretty=format:%ae | awk '// && !line{line=$0} END{print line}' + - name: Get PR Author Email Address + run: | + echo "The name of the pusher: ${{ github.event.pusher.name }}" + echo "The email of the pusher: ${{ github.event.pusher.email }}" + - run: | + curl -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/users/${{ github.actor }} + - run: | + curl -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + ${{ github.event.pull_request._links.commits.href }} + - run: ls -lart && pwd && ls -lart ../ && ls -lart ../../ + - run: git status + - run: python3 ../get-email/main.py diff --git a/docker/Dockerfile b/docker/Dockerfile index a8dd2c6..ae65479 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,3 +14,4 @@ RUN python3 -m venv ~/venv && echo "source ~/venv/bin/activate" >> ~/.bashrc RUN . ~/venv/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install -r /tmp/requirements.txt +RUN sudo apt-get update && sudo apt-get install -y jq diff --git a/get-email/main.py b/get-email/main.py index 7198bf5..9f7626f 100644 --- a/get-email/main.py +++ b/get-email/main.py @@ -7,15 +7,20 @@ from actions_toolkit.github import Context from github import Github from pydantic import BaseModel, Field +import requests import rich + # Create Github instance with provided token github_token = os.environ["GITHUB_TOKEN"] github = Github(github_token) + # Get current context (GitHub Actions context) context = Context() +import rich +rich.inspect(context, methods=True) # Fetch the repository information repo = github.get_repo("efcs/action") @@ -23,6 +28,20 @@ rich.inspect(commit) rich.print(commit) +def get_commits(): + headers = { + 'Accept': 'application/vnd.github+json', + 'Authorization': os.environ['GITHUB_TOKEN'], + 'X-GitHub-Api-Version': '2022-11-28' + } + + url = os.environ['PULL_REQUEST_COMMITS_HREF'] + + response = requests.get(url, headers=headers) + rich.print(response) + response.raise_for_status() + return response.json() + class Annotation(BaseModel): path: str @@ -52,20 +71,7 @@ class CheckRun(BaseModel): def main(): rich.print(context) - ''' - check_run = repo.create_check_run( - name="Libc++ Test Suite", - head_sha=context.sha, - status="completed", - conclusion=conclusion, - output={ - "title": "Check Run Output", - "summary": f"{len(annotations)} tests failed.", - "annotations": annotations - }, - ) - rich.print(check_run) - ''' + get_commits() if __name__ == "__main__":