Skip to content

Commit

Permalink
Merge pull request #1 from port-labs/fix-no-results-in-slack-report-a…
Browse files Browse the repository at this point in the history
…nd-add-verbosity
  • Loading branch information
Tankilevitch authored Nov 15, 2023
2 parents 723d561 + 6a69d16 commit 1ee21f1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-scorecard-reminder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecards Reminders
uses: port-labs/[email protected].14
uses: port-labs/[email protected].15
with:
message_kind: scorecard_reminder
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-scorecard-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecard Report
uses: port-labs/[email protected].14
uses: port-labs/[email protected].15
with:
message_kind: scorecard_report
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecard Report
uses: port-labs/[email protected].14
uses: port-labs/[email protected].15
with:
message_kind: scorecard_report
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecards Reminders
uses: port-labs/[email protected].14
uses: port-labs/[email protected].15
with:
message_kind: scorecard_reminder
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/generate-scorecard-reminder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecards Reminders
uses: port-labs/[email protected].14
uses: port-labs/[email protected].15
with:
message_kind: scorecard_reminder
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/generate-scorecard-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecard Report
uses: port-labs/[email protected].14
uses: port-labs/[email protected].15
with:
message_kind: scorecard_report
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
Expand Down
66 changes: 48 additions & 18 deletions generators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities:
"text": f"Here is a summary of the current {scorecard_title} scorecard status ⭐️"
}
},
]
if entities_by_level_text:
blocks += [
{
"type": "section",
"text": {
Expand All @@ -95,7 +98,26 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities:
"type": "mrkdwn",
"text": entities_by_level_text
}
},
}]
else:
blocks += [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*:vertical_traffic_light: {blueprint_plural} by level*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "There are no entities with scorecard data :disappointed:"
}
}
]
if top_teams_text:
blocks += [
{
"type": "section",
"text": {
Expand All @@ -107,10 +129,12 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities:
"type": "section",
"text": {
"type": "mrkdwn",
"text": top_teams_text if top_teams_text else
"There are no teams with scorecard data :disappointed:"
"text": top_teams_text
}
},
]
if top_highest_scored_rules_text:
blocks += [
{
"type": "section",
"text": {
Expand All @@ -124,21 +148,27 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities:
"type": "mrkdwn",
"text": top_highest_scored_rules_text
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:warning: Lowest scoring rules*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": top_lowest_scored_rules_text
}
},
}
]
if top_lowest_scored_rules_text:
blocks += [

{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:warning: Lowest scoring rules*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": top_lowest_scored_rules_text
}
},
]
blocks += [
{
"type": "section",
"text": {
Expand Down
5 changes: 4 additions & 1 deletion targets/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def __init__(self):
def send_message(self, blocks: List[Dict[str, Any]]):
logger.info(f"Sending message to slack channel")
response = self.webhook.send(blocks=blocks)
logger.info(f"Message sent to slack channel: {response.status_code}")
if response.status_code > 200:
raise Exception(f"Failed to send Message to slack channel: {response.status_code}, {response.body}, "
f"slack channel: {settings.slack_webhook_url}, blocks: {blocks}")
logger.info(f"Message sent to slack channel: {response.status_code}, {response.body}")
return response.status_code

0 comments on commit 1ee21f1

Please sign in to comment.