-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: check documentation for feature merge requests
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import sys | ||
import requests | ||
from urllib.parse import urlparse | ||
|
||
|
||
WEBSITE_REPOS = frozenset(("india-compliance-docs",)) | ||
DOCUMENTATION_DOMAINS = frozenset(("docs.indiacompliance.app",)) | ||
|
||
|
||
def is_valid_url(url: str) -> bool: | ||
parts = urlparse(url) | ||
return all((parts.scheme, parts.netloc, parts.path)) | ||
|
||
|
||
def is_documentation_link(word: str) -> bool: | ||
if not word.startswith("http") or not is_valid_url(word): | ||
return False | ||
|
||
parsed_url = urlparse(word) | ||
if parsed_url.netloc in DOCUMENTATION_DOMAINS: | ||
return True | ||
|
||
if parsed_url.netloc == "github.com": | ||
parts = parsed_url.path.split("/") | ||
if ( | ||
len(parts) == 5 | ||
and parts[1] == "resilient-tech" | ||
and parts[2] in WEBSITE_REPOS | ||
): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def contains_documentation_link(body: str) -> bool: | ||
return any( | ||
is_documentation_link(word) | ||
for line in body.splitlines() | ||
for word in line.split() | ||
) | ||
|
||
|
||
def check_pull_request(number: str) -> "tuple[int, str]": | ||
response = requests.get( | ||
f"https://api.github.com/repos/resilient-tech/india-compliance/pulls/{number}" | ||
) | ||
if not response.ok: | ||
return 1, "Pull Request Not Found! ⚠️" | ||
|
||
payload = response.json() | ||
title = (payload.get("title") or "").lower().strip() | ||
head_sha = (payload.get("head") or {}).get("sha") | ||
body = (payload.get("body") or "").lower() | ||
|
||
if ( | ||
not title.startswith("feat") | ||
or not head_sha | ||
or "no-docs" in body | ||
or "backport" in body | ||
): | ||
return 0, "Skipping documentation checks... 🏃" | ||
|
||
if contains_documentation_link(body): | ||
return 0, "Documentation Link Found. You're Awesome! 🎉" | ||
|
||
return 1, "Documentation Link Not Found! ⚠️" | ||
|
||
|
||
if __name__ == "__main__": | ||
exit_code, message = check_pull_request(sys.argv[1]) | ||
print(message) | ||
sys.exit(exit_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Documentation Required | ||
|
||
on: | ||
pull_request: | ||
types: [ opened, synchronize, reopened, edited ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- name: 'Setup Environment' | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Validate Docs | ||
env: | ||
PR_NUMBER: ${{ github.event.number }} | ||
run: | | ||
pip install requests --quiet | ||
python $GITHUB_WORKSPACE/.github/helper/documentation.py $PR_NUMBER |