Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage #20

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = test/*.py
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
permissions: # added using https://github.com/step-security/secure-repo
contents: read
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.x'
- name: Install poetry
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd # v3.0.1
- name: Run tests
run: |
poetry install --with test
poetry run coverage run --branch -m unittest discover -b
poetry run coverage xml
- name: Save debug.log file
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: always()
with:
name: debug-log
path: ./debug.log
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 # master
continue-on-error: true # added since if it's a PR from a different user account, the credentials won't pass over
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
18 changes: 9 additions & 9 deletions lfx_tac_actions/updateclomonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import yaml
import argparse
import urllib.request
import requests
import urllib.parse
import json
import os
Expand All @@ -17,12 +17,12 @@ def main():
parser.add_argument("-o", "--output", help="filename to save output to",default='_data/clomonitor.yaml')
args = parser.parse_args()

if os.environ.get("LANDSCAPE_URL") != '' and os.environ.get("ARTWORK_URL") != '':
if os.environ.get("LANDSCAPE_URL") != '':
landscape_hosted_projects = '{}/api/projects/all.json'.format(os.environ.get("LANDSCAPE_URL"))
project_entries = []

with urllib.request.urlopen(landscape_hosted_projects) as hosted_projects_response:
project_data = json.load(hosted_projects_response)
with requests.get(landscape_hosted_projects) as hosted_projects_response:
project_data = hosted_projects_response.json()
for project in project_data:
if project.get('maturity') == 'emeritus':
continue
Expand All @@ -33,8 +33,8 @@ def main():
logo_url_dark = ''
if project.get('artwork_url'):
urlparts = urllib.parse.urlparse(project.get('artwork_url'))
with urllib.request.urlopen('{}://{}/assets/data.json'.format(urlparts.scheme,urlparts.netloc)) as artwork_response:
artwork_data = json.load(artwork_response)
with requests.get('{}://{}/assets/data.json'.format(urlparts.scheme,urlparts.netloc)) as artwork_response:
artwork_data = artwork_response.json()
logo_url = '{}://{}{}{}'.format(urlparts.scheme,urlparts.netloc,urlparts.path,artwork_data.get(urlparts.path,{}).get('primary_logo'))
logo_url_dark = '{}://{}{}{}'.format(urlparts.scheme,urlparts.netloc,urlparts.path,artwork_data.get(urlparts.path,{}).get('dark_logo'))
else:
Expand All @@ -60,9 +60,9 @@ def main():
})
project_entries.append(project_entry)

with open(args.output, 'w') as clomonitor_file_object:
print("Saving file {}".format(args.output))
yaml.dump(project_entries, clomonitor_file_object, sort_keys=False, indent=2)
with open(args.output, 'w') as clomonitor_file_object:
print("Saving file {}".format(args.output))
yaml.dump(project_entries, clomonitor_file_object, sort_keys=False, indent=2)

if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions lfx_tac_actions/updateprojects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# encoding=utf8

import csv
import urllib.request
import requests
import json
import os
import argparse
Expand All @@ -20,8 +20,8 @@ def main():
landscape_hosted_projects = '{}/api/projects/all.json'.format(os.environ["LANDSCAPE_URL"])

csv_rows = []
with urllib.request.urlopen(landscape_hosted_projects) as hosted_projects_response:
project_data = json.load(hosted_projects_response)
with requests.get(landscape_hosted_projects) as hosted_projects_response:
project_data = hosted_projects_response.json()
for project in project_data:
categories = []
categories.append("{category} / {subcategory}".format(category=project.get('category'),subcategory=project.get('subcategory')))
Expand Down
6 changes: 3 additions & 3 deletions lfx_tac_actions/updatetacmembers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import argparse
import csv
import urllib.request
import requests
import json
import os
from urllib.parse import urlparse
Expand All @@ -23,8 +23,8 @@ def main():
committee_url = 'https://api-gw.platform.linuxfoundation.org/project-service/v2/public/projects/{project_id}/committees/{committee_id}/members'.format(project_id=urlparts[2],committee_id=urlparts[5])
csv_rows = []

with urllib.request.urlopen(committee_url) as committee_url_response:
committee_url_response_json = json.load(committee_url_response)
with requests.get(committee_url) as committee_url_response:
committee_url_response_json = committee_url_response.json()
for committee_member in committee_url_response_json.get('Data',[]):
print("Processing {} {}...".format(committee_member.get('FirstName').title(),committee_member.get('LastName').title()))
csv_rows.append({
Expand Down
Loading
Loading