Skip to content

Commit

Permalink
Implemented minor changes as per PR review feedback: README includes …
Browse files Browse the repository at this point in the history
…BOM generation expectation and link, ComponentData declared as a dataclass, API authentication failure handled with graceful exit, ExitStack usage removed, report template assets folder removed, font awesome icon implemented as standalone SVG and fonts removed.
  • Loading branch information
polypour committed Jul 12, 2024
1 parent da979cb commit fa1505e
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 9,140 deletions.
File renamed without changes.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# DigiKey-Reports
An actions repository for DigiKey API integration and report generation given an input BOM
# DigiKey-Search-HTML-Report
An actions repository for demonstrating DigiKey API integration and HTML report generation given an input BOM

This action uses the DigiKey API. See the [DigiKey API docs](https://developer.digikey.com/products) for more information.

Expand All @@ -8,10 +8,18 @@ This action uses the DigiKey API. See the [DigiKey API docs](https://developer.
Add the following step to your actions:

```yaml
- name: Generate BOM report using DigiKey
uses: https://hub.allspice.io/Actions/digikey-report@v1
- name: Generate HTML component report using DigiKey API
uses: https://hub.allspice.io/Actions/digikey-search-html-report.git@v1
with:
bom_file: bom.csv
digikey_client_id: ${{ secrets.DIGIKEY_CLIENT_ID }}
digikey_client_secret: ${{ secrets.DIGIKEY_CLIENT_SECRET }}
```
This add-on requires the DigiKey client ID and client secret to be stored as Actions secrets. Refer to the [knowledge base article on Actions secrets](https://learn.allspice.io/docs/secrets#actions-secrets) to learn how to add the required secrets to your repository.
## Input BOM
The input BOM to this Action is assumed to be generated from the py-allspice BOM generation utility. The column names referenced and used in this Action script assume the naming convention as populated by the py-allspice BOM generation function. The user is to adjust the expected column positions and naming conventions when using their own BOM file input.
A typical workflow is to use the [BOM generation Actions add-on](https://hub.allspice.io/Actions/generate-bom) to generate the BOM first, and use the generated BOM as an input to this Action.
55 changes: 31 additions & 24 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from jinja2 import Environment, FileSystemLoader
from argparse import ArgumentParser
from contextlib import ExitStack
from dataclasses import dataclass
import requests
import zipfile
import shutil
Expand All @@ -18,26 +18,26 @@


################################################################################
@dataclass
class ComponentData:
def __init__(self):
self.associated_refdes = ""
self.part_description = None
self.mfr_name = None
self.mfr_part_number = None
self.photo_url = None
self.datasheet_url = None
self.product_url = None
self.qty_available = None
self.lifecycle_status = None
self.eol_status = None
self.discontinued_status = None
self.pricing = None
self.package_case = None
self.supplier_device_package = None
self.operating_temp = None
self.xy_size = None
self.height = None
self.thickness = None
associated_refdes: str = ""
part_description: str = None
mfr_name: str = None
mfr_part_number: str = None
photo_url: str = None
datasheet_url: str = None
product_url: str = None
qty_available: str = None
lifecycle_status: str = None
eol_status: str = None
discontinued_status: str = None
pricing: str = None
package_case: str = None
supplier_device_package: str = None
operating_temp: str = None
xy_size: str = None
height: str = None
thickness: str = None


################################################################################
Expand Down Expand Up @@ -210,6 +210,13 @@ def extract_data_from_digikey_search_response(keyword_search_json):
DIGIKEY_API_AUTH_ENDPOINT, digikey_client_id, digikey_client_secret
)

# Cannot proceed with search API queries if authentication failed,
# exit gracefully.
if response_code != 200:
print("Authentication failed. Response from server:")
print(access_token)
print("Exiting...")

# Initialize list of BOM item part data
bom_items_digikey_data = []

Expand Down Expand Up @@ -237,6 +244,7 @@ def extract_data_from_digikey_search_response(keyword_search_json):
bom_items_digikey_data.append(part_data)
# Print out the details of an unsuccessful response
else:
print("DigiKey API search unsuccesful:")
print(response_code, keyword_search_json)

# Load Jinja with output HTML template
Expand All @@ -252,10 +260,9 @@ def extract_data_from_digikey_search_response(keyword_search_json):
# Unzip the JS/CSS assets
shutil.unpack_archive("/report_template/assets.zip", "/component_report")
# Write HTML output file
with ExitStack() as stack:
report_file = stack.enter_context(
open("/component_report/index.html", mode="w", encoding="utf-8")
)
with open(
"/component_report/index.html", mode="w", encoding="utf-8"
) as report_file:
print("- Outputting report")
report_file.write(template.render(context))
# Zip the component report as a git workspace artifact
Expand Down
Binary file modified report_template/assets.zip
Binary file not shown.
5 changes: 0 additions & 5 deletions report_template/assets/bootstrap/css/bootstrap.min.css

This file was deleted.

6 changes: 0 additions & 6 deletions report_template/assets/bootstrap/js/bootstrap.min.js

This file was deleted.

57 changes: 0 additions & 57 deletions report_template/assets/css/Navbar-Right-Links-Dark-icons.css

This file was deleted.

Binary file removed report_template/assets/fonts/fa-brands-400.eot
Binary file not shown.
Loading

0 comments on commit fa1505e

Please sign in to comment.