Changed the rules of yamllint and fixed warnings and errors (#1011)

* updated rules of yamllint

* fix: lint warning in maintainers file

* fix: lint warning in projects file

* fix: lint warning and error in social good file

* trailing space rule removed for yamllint

* added name for the workflow and updated the job name

* security fix for website pr validation flow

* remove thank you workflow

* switched to file.write instead of system function

* bug fix
This commit is contained in:
Abhinav Rajesh 2022-10-07 09:22:22 +05:30 коммит произвёл GitHub
Родитель cedfe96607
Коммит 6b16d78ed8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 30 добавлений и 101 удалений

Просмотреть файл

@ -1,17 +0,0 @@
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 }}

28
.github/workflows/website-pr-validation.yml поставляемый
Просмотреть файл

@ -1,24 +1,17 @@
name: Validate PR for githubindia.com website name: Validate PR for githubindia.com website
on: on:
pull_request_target: pull_request:
branches: branches:
- main - main
paths: paths:
- "website/**" - "website/**"
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout head branch of PR - name: Checkout repo
uses: actions/checkout@v3 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 - name: Check format of yaml file
id: yaml-lint id: yaml-lint
uses: ibiqlik/action-yamllint@v3 uses: ibiqlik/action-yamllint@v3
@ -26,7 +19,6 @@ jobs:
strict: true strict: true
file_or_dir: website/**/*.yml file_or_dir: website/**/*.yml
config_data: | config_data: |
extends: default
rules: rules:
empty-lines: empty-lines:
max: 1 max: 1
@ -38,7 +30,6 @@ jobs:
check-multi-line-strings: false check-multi-line-strings: false
new-lines: new-lines:
type: unix type: unix
trailing-spaces: enable
colons: colons:
max-spaces-before: 0 max-spaces-before: 0
max-spaces-after: 1 max-spaces-after: 1
@ -50,24 +41,21 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: lint needs: lint
steps: steps:
- name: Checkout head branch of PR - name: Checkout fork
uses: actions/checkout@v3 uses: actions/checkout@v3
with: - name: Checkout main
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 uses: actions/checkout@v3
with: with:
ref: main ref: main
repository: github/india
path: ./india-main path: ./india-main
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1
with: with:
ruby-version: 3.0.0 ruby-version: 3.0.0
- name: Validate PR - name: Validate PR
run: | run: |
gem install octokit gem install octokit safe_yaml
ruby india-main/script/website-pr-validation.rb ruby india-main/script/website-pr-validation.rb
env: env:
PR_ID: ${{ github.event.number }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAT: ${{ secrets.PAT }}
INDIA_REPO_NWO: ${{ secrets.INDIA_REPO_NWO }} INDIA_REPO_NWO: ${{ secrets.INDIA_REPO_NWO }}

Просмотреть файл

@ -1,15 +1,13 @@
require "rubygems" require "rubygems"
require "octokit" require "octokit"
require "yaml"
require "json" require "json"
require "logger" require "logger"
require "safe_yaml"
@logger = Logger.new(STDOUT) CLIENT = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
CLIENT = Octokit::Client.new(:access_token => ENV["PAT"])
REPOSITORY= ENV["INDIA_REPO_NWO"] REPOSITORY= ENV["INDIA_REPO_NWO"]
BASE_PATH = "website/data/open-source" BASE_PATH = "website/data/open-source"
PR_ID = ENV["PR_ID"] @logger = Logger.new(STDOUT)
# Flag for checking if the issues are present # Flag for checking if the issues are present
$ISSUES_PRESENT = false $ISSUES_PRESENT = false
@ -27,12 +25,12 @@ def waitTillLimitReset
sleep(timeTillReset) sleep(timeTillReset)
end 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: # Params:
# category: Category of the issue (maintainers/ossProjects/socialGoodProjects) # category: Category of the issue (maintainers/ossProjects/socialGoodProjects)
# issues: Array of issues present for the PR # issues: Array of issues present for the PR
# title: Name of the project/maintainer # title: Name of the project/maintainer
def preparePRComments(category, issues, title) def prepareJobSummary(category, issues, title)
$ISSUES_PRESENT = true $ISSUES_PRESENT = true
body = { body = {
:title => title, :title => title,
@ -47,8 +45,8 @@ def preparePRComments(category, issues, title)
end end
end end
# Function to create the comment in the PR # Function to create job summary
def makePRComment def createJobSummary
comment = "PR cannot be merged due to following issues:\n" comment = "PR cannot be merged due to following issues:\n"
if MAINTAINERS_FAILED_VALIDATION.length() != 0 if MAINTAINERS_FAILED_VALIDATION.length() != 0
comment += "- Maintainers\n" comment += "- Maintainers\n"
@ -77,8 +75,8 @@ def makePRComment
end end
end end
end end
@logger.info("Commenting: #{comment}") @logger.info("Summary: #{comment}")
CLIENT.add_comment(REPOSITORY, PR_ID, comment) File.write(ENV["GITHUB_STEP_SUMMARY"], comment)
end end
# Function for fetching the details of a maintainer # Function for fetching the details of a maintainer
@ -114,7 +112,7 @@ end
# Function for validating if the project is valid # Function for validating if the project is valid
# Returns: Array of failed checks # Returns: Array of failed checks
def validateProject(data, isSocialGood) def validateProject(data, isSocialGood = false)
fails = [] fails = []
# Check if project is private # Check if project is private
if data.private if data.private
@ -125,7 +123,7 @@ def validateProject(data, isSocialGood)
fails.push("Project doesn't have a license") fails.push("Project doesn't have a license")
end end
# Check if project has atleast 100 stars # 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") fails.push("Project has less than 100 stars")
end end
return fails return fails
@ -135,7 +133,7 @@ end
# from the maintainers list at {BASE_PATH}/maintainers.yml # from the maintainers list at {BASE_PATH}/maintainers.yml
# and check if the maintainers are valid or not # and check if the maintainers are valid or not
def checkMaintainersData() 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 city in maintainersList.keys do
for maintainerName in maintainersList[city] do for maintainerName in maintainersList[city] do
begin begin
@ -170,7 +168,7 @@ end
# - Indicates the file location of the list of projects present # - Indicates the file location of the list of projects present
# - Values can be either "projects.yml" or "social-good-projects.yml" # - Values can be either "projects.yml" or "social-good-projects.yml"
def checkProjectsData(fileName) 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" if fileName == "projects.yml"
issueCategory = "ossProjects" issueCategory = "ossProjects"
else else
@ -206,65 +204,23 @@ def checkProjectsData(fileName)
end end
end end
# Check if any new maintainer is added @logger.info("-------------------------------")
# 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
@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
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
@logger.info("PR author cannot be the reviewer")
else
@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() checkMaintainersData()
@logger.info("Maintainers data checked") @logger.info("Maintainers data checked")
@logger.info("-------------------------------")
@logger.info("Checking OSS Projects...") @logger.info("Checking OSS Projects...")
checkProjectsData("projects.yml") checkProjectsData("projects.yml")
@logger.info("OSS Projects data checked") @logger.info("OSS Projects data checked")
@logger.info("-------------------------------")
@logger.info("Checking Social Good Projects...") @logger.info("Checking Social Good Projects...")
checkProjectsData("social-good-projects.yml") checkProjectsData("social-good-projects.yml")
@logger.info("Social Good Projects data checked") @logger.info("Social Good Projects data checked")
@logger.info("-------------------------------")
@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")
if MAINTAINERS_FAILED_VALIDATION.length() != 0 || OSSPROJECTS_FAILED_VALIDATION.length() != 0 || SOCIALGOOD_FAILED_VALIDATION.length() != 0 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() createPRSummary()
exit(1) exit(1)
end end
# Check if the changes are present in maintainers file @logger.info("-------------------------------")
checkMaintainersFileChanged()

Просмотреть файл

@ -1,3 +1,4 @@
---
Karnataka: Karnataka:
- knadh - knadh
- pranavrajs - pranavrajs

Просмотреть файл

@ -1,3 +1,4 @@
---
Developer Productivity & Tools: Developer Productivity & Tools:
- hoppscotch/hoppscotch - hoppscotch/hoppscotch
- hasura/graphql-engine - hasura/graphql-engine

Просмотреть файл

@ -1,3 +1,4 @@
---
Social Good Projects: Social Good Projects:
- egovernments/DIVOC - egovernments/DIVOC
- coronasafe/care - coronasafe/care
@ -6,4 +7,3 @@ Social Good Projects:
- Sunbird-Ed/SunbirdEd-portal - Sunbird-Ed/SunbirdEd-portal
- beckn/protocol-specifications - beckn/protocol-specifications
- glific/glific - glific/glific