Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mvkaran authored Oct 18, 2022
2 parents 18f157d + da47d2e commit f0101bf
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 87 deletions.
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 }}" }'
48 changes: 39 additions & 9 deletions .github/workflows/website-pr-validation.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
name: Validate PR for githubindia.com website
on:
pull_request_target:
pull_request:
branches:
- main
paths:
- "website/**"

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout head branch of PR
- name: Checkout repo
uses: actions/checkout@v3
- name: Check format of yaml file
id: yaml-lint
uses: ibiqlik/action-yamllint@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
strict: true
file_or_dir: website/**/*.yml
config_data: |
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
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 fork
uses: actions/checkout@v3
- name: Checkout main
uses: actions/checkout@v3
with:
ref: main
repository: github/india
path: ./india-main
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.0
- name: Validate PR
run: |
gem install octokit
gem install octokit safe_yaml
ruby india-main/script/website-pr-validation.rb
env:
PR_ID: ${{ github.event.number }}
PAT: ${{ secrets.PAT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INDIA_REPO_NWO: ${{ secrets.INDIA_REPO_NWO }}
108 changes: 32 additions & 76 deletions script/website-pr-validation.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require "rubygems"
require "octokit"
require "yaml"
require "json"
require "logger"
require "safe_yaml"

logger = Logger.new(STDOUT)

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

# Flag for checking if the issues are present
$ISSUES_PRESENT = false
Expand All @@ -23,16 +21,16 @@
# 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

# Function to preparing the comments to add to the PR if it has any issues
# Function to prepare the job summary to be added to the PR if it has any issues
# Params:
# category: Category of the issue (maintainers/ossProjects/socialGoodProjects)
# issues: Array of issues present for the PR
# title: Name of the project/maintainer
def preparePRComments(category, issues, title)
def prepareJobSummary(category, issues, title)
$ISSUES_PRESENT = true
body = {
:title => title,
Expand All @@ -47,8 +45,8 @@ def preparePRComments(category, issues, title)
end
end

# Function to create the comment in the PR
def makePRComment
# Function to create job summary
def createJobSummary
comment = "PR cannot be merged due to following issues:\n"
if MAINTAINERS_FAILED_VALIDATION.length() != 0
comment += "- Maintainers\n"
Expand Down Expand Up @@ -77,8 +75,8 @@ def makePRComment
end
end
end
puts comment
CLIENT.add_comment(REPOSITORY, PR_ID, comment)
@logger.info("Summary: #{comment}")
File.write(ENV["GITHUB_STEP_SUMMARY"], comment)
end

# Function for fetching the details of a maintainer
Expand Down Expand Up @@ -114,7 +112,7 @@ def getProject(projectName)

# Function for validating if the project is valid
# Returns: Array of failed checks
def validateProject(data, isSocialGood)
def validateProject(data, isSocialGood = false)
fails = []
# Check if project is private
if data.private
Expand All @@ -125,7 +123,7 @@ def validateProject(data, isSocialGood)
fails.push("Project doesn't have a license")
end
# Check if project has atleast 100 stars
if data.stargazers_count < 100 and !isSocialGood
if data.stargazers_count < 100 && !isSocialGood
fails.push("Project has less than 100 stars")
end
return fails
Expand All @@ -135,7 +133,7 @@ def validateProject(data, isSocialGood)
# from the maintainers list at {BASE_PATH}/maintainers.yml
# and check if the maintainers are valid or not
def checkMaintainersData()
maintainersList = JSON.parse(YAML.load(File.open("#{BASE_PATH}/maintainers.yml")).to_json)
maintainersList = JSON.parse(YAML.load(File.open("#{BASE_PATH}/maintainers.yml"), :safe => true).to_json)
for city in maintainersList.keys do
for maintainerName in maintainersList[city] do
begin
Expand All @@ -145,7 +143,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 +152,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 All @@ -170,7 +168,7 @@ def checkMaintainersData()
# - Indicates the file location of the list of projects present
# - Values can be either "projects.yml" or "social-good-projects.yml"
def checkProjectsData(fileName)
projectsList = JSON.parse(YAML.load(File.open("#{BASE_PATH}/#{fileName}")).to_json)
projectsList = JSON.parse(YAML.load(File.open("#{BASE_PATH}/#{fileName}"), :safe => true).to_json)
if fileName == "projects.yml"
issueCategory = "ossProjects"
else
Expand All @@ -189,7 +187,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,73 +196,31 @@ 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
end
end
end

# Check if any new maintainer is added
# If yes -> Add the maintainer as reviewer
def checkMaintainersFileChanged
maintainersListPR = JSON.parse(YAML.load(File.open("#{BASE_PATH}/maintainers.yml")).to_json)
maintainersList = JSON.parse(YAML.load(File.open("india-main/#{BASE_PATH}/maintainers.yml")).to_json)
maintainersMain = []
maintainersPR = []
for maintainers in maintainersList.values do
maintainersMain += maintainers
end
for maintainers in maintainersListPR.values do
maintainersPR += maintainers
end
newMaintainers = maintainersPR - maintainersMain
pullRequestDetails = CLIENT.pull_request(REPOSITORY, PR_ID)
newMaintainers.delete(pullRequestDetails.user.login)
if newMaintainers.length() > 10
puts "More than 10 maintainers added"
CLIENT.add_comment(REPOSITORY, PR_ID, "Cannot add more than 10 maintainers in a single PR")
exit(1)
end
if newMaintainers.length() != 0
begin
CLIENT.request_pull_request_review(REPOSITORY, PR_ID, reviewers: newMaintainers)
rescue => e
# PR author cannot add himself as reviewer
if e.response_status == 422
puts "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}"
end
end
end
end

logger.info("Checking Maintainers...")
@logger.info("-------------------------------")
@logger.info("Checking Maintainers...")
checkMaintainersData()
logger.info("Maintainers data checked")
logger.info("Checking OSS Projects...")
@logger.info("Maintainers data checked")
@logger.info("-------------------------------")
@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("-------------------------------")
@logger.info("Checking Social Good Projects...")
checkProjectsData("social-good-projects.yml")
logger.info("Social Good Projects data checked")

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("Social Good Projects data checked")
@logger.info("-------------------------------")

if MAINTAINERS_FAILED_VALIDATION.length() != 0 || OSSPROJECTS_FAILED_VALIDATION.length() != 0 || SOCIALGOOD_FAILED_VALIDATION.length() != 0
logger.info("Creating Comment")
makePRComment()
@logger.info("Creating Comment")
createPRSummary()
exit(1)
end
# Check if the changes are present in maintainers file
checkMaintainersFileChanged()
@logger.info("-------------------------------")
9 changes: 8 additions & 1 deletion website/data/open-source/maintainers.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
Karnataka:
- knadh
- pranavrajs
Expand All @@ -12,6 +13,7 @@ Karnataka:
- codesome
- blenderskool
- saiyam1814
- Samyak2

Kerala:
- gautamkrishnar
Expand Down Expand Up @@ -39,8 +41,12 @@ West Bengal:
- one-aalam
- 0xInfection

Chhattisgarh:
- abhisheknaiidu

Gujarat:
- amitmerchant1990
- amitmerchant1990
- harshzalavadiya

Other States:
- shivammathur
Expand All @@ -53,3 +59,4 @@ Other States:
- palashgdev
- thetutlage
- akshitagupta15june
- s0md3v
5 changes: 5 additions & 0 deletions website/data/open-source/projects.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
Developer Productivity & Tools:
- hoppscotch/hoppscotch
- hasura/graphql-engine
Expand All @@ -15,6 +16,7 @@ Developer Productivity & Tools:
- Delta456/box-cli-maker
- meshery/meshery
- nikochiko/autosaved
- Samyak2/toipe

Observability:
- signoz/signoz
Expand All @@ -38,6 +40,7 @@ UI/UX:
- CRED-CLUB/synth-android
- ParthJadhav/Tkinter-Designer
- resuminator/resuminator
- hc-oss/react-multi-select-component

Data Science & Engineering:
- activeloopai/Hub
Expand All @@ -58,12 +61,14 @@ GitHub Power-Ups:
- anuraghazra/github-readme-stats
- shivammathur/setup-php
- gautamkrishnar/blog-post-workflow
- abhisheknaiidu/awesome-github-profile-readme

Business Software:
- frappe/erpnext
- chatwoot/chatwoot
- bagisto/bagisto
- knadh/listmonk
- chaos-genius/chaos_genius

Consumer Software:
- kovidgoyal/calibre
Expand Down
2 changes: 1 addition & 1 deletion website/data/open-source/social-good-projects.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
Social Good Projects:
- egovernments/DIVOC
- coronasafe/care
Expand All @@ -6,4 +7,3 @@ Social Good Projects:
- Sunbird-Ed/SunbirdEd-portal
- beckn/protocol-specifications
- glific/glific

0 comments on commit f0101bf

Please sign in to comment.