{"id":20484657,"url":"https://github.com/sap-samples/github-pull-analyzer","last_synced_at":"2025-03-05T16:20:23.396Z","repository":{"id":236272114,"uuid":"788101238","full_name":"SAP-samples/github-pull-analyzer","owner":"SAP-samples","description":"The GitHub Pull Request Analyzer (with SAP AI Core) automates the task of analyzing pull request in GitHub, summarizing the themes, sentiments, points of resonation/repulsion, and difficulties in the collected interactions.","archived":false,"fork":false,"pushed_at":"2024-04-29T09:48:37.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-16T04:27:31.812Z","etag":null,"topics":["btp","github","llm","nlp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SAP-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-17T19:22:48.000Z","updated_at":"2024-11-03T14:38:53.000Z","dependencies_parsed_at":"2024-04-29T10:55:59.051Z","dependency_job_id":"75daf840-9043-4de3-a57b-49c8965e1f9b","html_url":"https://github.com/SAP-samples/github-pull-analyzer","commit_stats":null,"previous_names":["sap-samples/btp-llm-github-pull-analyzer","sap-samples/github-pull-analyzer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fgithub-pull-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fgithub-pull-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fgithub-pull-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fgithub-pull-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAP-samples","download_url":"https://codeload.github.com/SAP-samples/github-pull-analyzer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242058329,"owners_count":20065088,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["btp","github","llm","nlp"],"created_at":"2024-11-15T16:24:57.645Z","updated_at":"2025-03-05T16:20:23.374Z","avatar_url":"https://github.com/SAP-samples.png","language":"Python","readme":"# GitHub Pull Request Analyzer (with SAP AI Core)\n\n[![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/github-pull-analyzer)](https://api.reuse.software/info/github.com/SAP-samples/github-pull-analyzer)\n\nThe GitHub Pull Request Analyzer (with SAP AI Core) automates the task of analyzing pull request in GitHub, summarizing the themes, sentiments, points of resonation/repulsion, and difficulties in the collected interactions. The results are outputted as a JSON report which is easy to parse and process.\n\n## Files in the Source Code\n\n- [**main.py**](program/main.py) - Main driver of the program. It sets up logging, parsing command-line arguments, loading configuration, generating and processing the report.\n- [**config.py**](program/config.py) - Contains classes to configure and load configuration from a JSON manifest.\n- [**providers.py**](program/providers.py) - Contains classes that provide the interaction with the GitHub and OpenAI LLM APIs.\n- [**report.py**](program/report.py) - Contains classes that generate and process the report based on the provided configuration and data retrieved from APIs.\n\n## Files in the Source Code\n\n- [**main.py**](program/main.py) - Main driver of the program. It sets up logging, parsing command-line arguments, loading configuration, generating and processing the report.\n- [**config.py**](program/config.py) - Contains classes to configure and load configuration from a JSON manifest.\n- [**providers.py**](program/providers.py) - Contains classes that provide the interaction with the GitHub and OpenAI LLM APIs.\n- [**report.py**](program/report.py) - Contains classes that generate and process the report based on the provided configuration and data retrieved from APIs.\n\n## Setup \u0026 Run the Utility Locally\n\nTo setup a local environment and run the program from scratch, perform the following steps:\n\n### Prerequisites\n\n- **Python** - Execution engine\n- **Poetry** - Modern package manager for Python\n- **GitHub** - Authorized access to GitHub API\n  - See [GitHub REST API documentation](https://docs.github.com/en/rest)\n- **SAP AI Core** - Authorized access to OpenAI Completions API via SAP AI Core\n  - See [Generative AI Hub in SAP AI Core](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/models-and-scenarios-in-generative-ai-hub) for setup instructions\n\n### Configuration\n\nThe manifest.json file configures the analyzer and should be set up as follows:\n\n```json\n{\n    \"github\": {\n        \"org_name\": \"mock-org\",\n        \"repo_name\": \"mock-repo\",\n        \"api_url\": \"https://\u003cgithub-url\u003e/api/v3\",\n        \"api_token\": (str),\n        \"search_label\": (str)\n    },\n    \"openai\": {\n        \"completions_url\": \"https://\u003cbtp-llm-proxy-url\u003e/chat/completions?api-version=\u003cversion\u003e\",\n        \"uaa_url\": \"https://\u003cbtp-uaa-authentication-url\u003e\",\n        \"client_id\": (str),\n        \"client_secret\": (str),\n        \"data_template\": {\n            \"deployment_id\": \"gpt-4-32k\",\n            \"messages\": [],\n            \"max_tokens\": 4000,\n            \"temperature\": 0.7,\n            \"frequency_penalty\": 0,\n            \"presence_penalty\": 0,\n            \"top_p\": 0.95,\n            \"stop\": null\n        }\n    },\n    \"report\": {\n        \"grounding_prompt\": \"Interactions between the requestor (user) and reviewer(s) (assistant)\",\n        \"pull_prompt\": \"Summarize the themes, sentiments, points of resonation, points of repulsion and difficulties for this interaction\",\n        \"overview_prompt\": \"Summarize the themes, sentiments, points of resonation, points of repulsion and difficulties in aggregate for all interactions\"\n    }\n}\n```\n\nDuring the runtime:\n\n* The manifest is expected to be input through the standard input stream (stdin)\n* All logging output (INFO, DEBUG, ERROR) is directed through the standard error stream (stderr)\n* The resulting final report JSON is delivered through the standard output stream (stdout)\n\n### Execution\n\n1. **Clone the Source Code Repository**\n\n```bash\ngit clone \u003curl-to-repo\u003e\ncd \u003crepo-dir\u003e\n```\n\n2. **Setup the Python Environment Using Poetry**\n\n```bash\npoetry shell\n```\n\n3. **Install Dependencies**\n\n```bash\npoetry install\n```\n\n4. **Running Unit Tests with verbose logging**\n\n```bash\npoetry run pytest --verbose\n```\n\n5. **Running Unit Tests normally**\n\n```bash\npoetry run pytest\n```\n\n6. **Running the Program to display help**\n\n```bash\npoetry run python3 -m program.main -h\n```\n\n7. **Running the Program with verbose logging**\n\n```bash\n# Adjust as appropriate\nMANIFEST_JSON_PATH=~/Downloads/mock/manifest.json\nSUMMARY_LOG_PATH=~/Downloads/mock/summary.log\nSUMMARY_JSON_PATH=~/Downloads/mock/summary.json\n\ncat ${MANIFEST_JSON_PATH} | \\\n    poetry run python3 -m program.main --verbose \\\n    2\u003e ${SUMMARY_LOG_PATH} | jq '.' \\\n    \u003e ${SUMMARY_JSON_PATH}\n```\n\n8. **Running the Program normally**\n\n```bash\n# Adjust as appropriate\nMANIFEST_JSON_PATH=~/Downloads/mock/manifest.json\nSUMMARY_LOG_PATH=~/Downloads/mock/summary.log\nSUMMARY_JSON_PATH=~/Downloads/mock/summary.json\n\ncat ${MANIFEST_JSON_PATH} | \\\n    poetry run python3 -m program.main \\\n    2\u003e ${SUMMARY_LOG_PATH} | jq '.' \\\n    \u003e ${SUMMARY_JSON_PATH}\n```\n\n9. **Useful jq queries**\n\n```bash\n# Adjust as appropriate\nSUMMARY_JSON_PATH=~/Downloads/mock/summary.json\n\njq -r '.pulls[] | .url' ${SUMMARY_JSON_PATH} | wc -l\njq -r '.pulls[] | .url' ${SUMMARY_JSON_PATH}\njq -r '.pulls[] | .analysis' ${SUMMARY_JSON_PATH}\njq -r '.summary' ${SUMMARY_JSON_PATH}\n```\n\n## How to obtain support\n\n[Create an issue](https://github.com/SAP-samples/btp-llm-github-pull-analyzer/issues) in this repository if you find a bug or have questions about the content.\n\nFor additional support, [ask a question in SAP Community](https://answers.sap.com/questions/ask.html).\n\n## Contributing\n\nIf you wish to contribute code, offer fixes or improvements, please send a pull request. Due to legal reasons, contributors will be asked to accept a DCO when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).\n\n## License\n\nCopyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fgithub-pull-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsap-samples%2Fgithub-pull-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fgithub-pull-analyzer/lists"}