Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
nehagup authored Oct 4, 2022
2 parents 8e96a80 + cedfe96 commit 237c63d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 22 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/create-thank-you-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
pull_request:
types:
- opened
paths:
- "website/**"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: mshick/add-pr-comment@v1
with:
message: |
Thank you for your contribution @${{ github.event.pull_request.user.login }} :blue_heart:
We will review your PR soon.
repo-token: ${{ secrets.MAINTAINER_PAT }}
19 changes: 19 additions & 0 deletions .github/workflows/trigger-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Trigger build
on:
pull_request:
types:
- closed
paths:
- "website/**"
jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Trigger build
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Trigger build when public PR is merged
token: ${{ secrets.PAT }}
repo: ${{ secrets.GITHUBINDIA_REPO_NWO }}
inputs: '{"pr_number": "${{ github.event.number }}", "creator_username": "${{ github.event.pull_request.user.login }}" }'
44 changes: 43 additions & 1 deletion .github/workflows/website-pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,49 @@ on:
paths:
- "website/**"
jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout head branch of PR
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout main branch of github/india repo
uses: actions/checkout@v3
with:
ref: main
path: ./india-main
- name: Check format of yaml file
id: yaml-lint
uses: ibiqlik/action-yamllint@v3
with:
strict: true
file_or_dir: website/**/*.yml
config_data: |
extends: default
rules:
empty-lines:
max: 1
hyphens:
max-spaces-after: 1
indentation:
spaces: consistent
indent-sequences: true
check-multi-line-strings: false
new-lines:
type: unix
trailing-spaces: enable
colons:
max-spaces-before: 0
max-spaces-after: 1
empty-values:
forbid-in-block-mappings: true
key-duplicates: false
format: github
validate:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout head branch of PR
uses: actions/checkout@v3
Expand All @@ -29,3 +70,4 @@ jobs:
env:
PR_ID: ${{ github.event.number }}
PAT: ${{ secrets.PAT }}
INDIA_REPO_NWO: ${{ secrets.INDIA_REPO_NWO }}
42 changes: 21 additions & 21 deletions script/website-pr-validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
require "json"
require "logger"

logger = Logger.new(STDOUT)
@logger = Logger.new(STDOUT)

CLIENT = Octokit::Client.new(:access_token => ENV["PAT"])
REPOSITORY="github/india"
REPOSITORY= ENV["INDIA_REPO_NWO"]
BASE_PATH = "website/data/open-source"
PR_ID = ENV["PR_ID"]

Expand All @@ -23,7 +23,7 @@
# Function to sleep the script for sometime when the API limit is hit
def waitTillLimitReset
timeTillReset = CLIENT.rate_limit.resets_in + 5
puts "API limit reached while fetching... Sleeping for #{timeTillReset} seconds 😴 brb"
@logger.info("API limit reached while fetching... Sleeping for #{timeTillReset} seconds 😴 brb")
sleep(timeTillReset)
end

Expand Down Expand Up @@ -77,7 +77,7 @@ def makePRComment
end
end
end
puts comment
@logger.info("Commenting: #{comment}")
CLIENT.add_comment(REPOSITORY, PR_ID, comment)
end

Expand Down Expand Up @@ -145,7 +145,7 @@ def checkMaintainersData()
preparePRComments("maintainers", issues, maintainerName)
end
rescue => e
puts "Error #{e.response_status}"
@logger.info("Error #{e.response_status}")
if e.response_status == 403
waitTillLimitReset()
maintainer = getMaintainer(maintainerName)
Expand All @@ -154,7 +154,7 @@ def checkMaintainersData()
preparePRComments("maintainers", issues, maintainerName)
end
else
puts "Error on maintainer: #{maintainerName}"
@logger.info("Error on maintainer: #{maintainerName}")
preparePRComments("maintainers", ["User with username #{maintainerName} doesn't exist!"], maintainerName)
end
end
Expand Down Expand Up @@ -189,7 +189,7 @@ def checkProjectsData(fileName)
preparePRComments(issueCategory, issues, projectName)
end
rescue => e
puts "Error: #{e.response_status}"
@logger.info("Error: #{e.response_status}")
if e.response_status == 403
waitTillLimitReset()
project = getProject(projectName)
Expand All @@ -198,7 +198,7 @@ def checkProjectsData(fileName)
preparePRComments(issueCategory, issues, projectName)
end
else
puts "Error on project: #{projectName}"
@logger.info("Error on project: #{projectName}")
preparePRComments(issueCategory, ["Project #{projectName} is either private or doesn't exist!"], projectName)
end
end
Expand All @@ -223,7 +223,7 @@ def checkMaintainersFileChanged
pullRequestDetails = CLIENT.pull_request(REPOSITORY, PR_ID)
newMaintainers.delete(pullRequestDetails.user.login)
if newMaintainers.length() > 10
puts "More than 10 maintainers added"
@logger.info("More than 10 maintainers added")
CLIENT.add_comment(REPOSITORY, PR_ID, "Cannot add more than 10 maintainers in a single PR")
exit(1)
end
Expand All @@ -233,36 +233,36 @@ def checkMaintainersFileChanged
rescue => e
# PR author cannot add himself as reviewer
if e.response_status == 422
puts "PR author cannot be the reviewer"
@logger.info("PR author cannot be the reviewer")
else
puts "ERROR STATUS: #{e.response_status}"
puts "An error of type #{e.class} happened, message is #{e.message}"
@logger.info("ERROR STATUS: #{e.response_status}")
@logger.info("An error of type #{e.class} happened, message is #{e.message}")
end
end
end
end

logger.info("Checking Maintainers...")
@logger.info("Checking Maintainers...")
checkMaintainersData()
logger.info("Maintainers data checked")
logger.info("Checking OSS Projects...")
@logger.info("Maintainers data checked")
@logger.info("Checking OSS Projects...")
checkProjectsData("projects.yml")
logger.info("OSS Projects data checked")
logger.info("Checking Social Good Projects...")
@logger.info("OSS Projects data checked")
@logger.info("Checking Social Good Projects...")
checkProjectsData("social-good-projects.yml")
logger.info("Social Good Projects data checked")
@logger.info("Social Good Projects data checked")

logger.info("Adding Labels...")
@logger.info("Adding Labels...")
# Add valid/not valid label if the PR has issue or not
if $ISSUES_PRESENT
CLIENT.add_labels_to_an_issue(REPOSITORY, PR_ID, ["githubindia.com", "invalid"])
else
CLIENT.add_labels_to_an_issue(REPOSITORY, PR_ID, ["githubindia.com", "valid"])
end
logger.info("Added Labels")
@logger.info("Added Labels")

if MAINTAINERS_FAILED_VALIDATION.length() != 0 || OSSPROJECTS_FAILED_VALIDATION.length() != 0 || SOCIALGOOD_FAILED_VALIDATION.length() != 0
logger.info("Creating Comment")
@logger.info("Creating Comment")
makePRComment()
exit(1)
end
Expand Down

0 comments on commit 237c63d

Please sign in to comment.