Skip to content

Commit

Permalink
add more docs examples and returned ordered
Browse files Browse the repository at this point in the history
  • Loading branch information
Tankilevitch committed Nov 8, 2023
1 parent c25a3ee commit be7bdc2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
55 changes: 49 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,59 @@

Port is the Developer Platform meant to supercharge your DevOps and Developers, and allow you to regain control of your environment.

### Docs

- [Port Docs](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/ci-cd/github-workflow/)
## Send Scorecard Report

## Usage
Action to send a scorecard report to a Slack channel about the current metrics of a scorecard.

See [action.yml](action.yml) for inputs and outputs.
### example

![Scorecard Report](docs/assets/scorecard-report.png)

![Generate Scorecard Report](docs/assets/generate-scorecard-report.png)
### Usage

| Input | Description | Required | Default |
| ----- |-----------------------------------------------------------------------------------------------------------|----------| ------- |
| `port_client_id` | Port Client ID | true | |
| `port_client_secret` | Port Client Secret | true | |
| `slack_webhook_url` | Slack Webhook URL | true | |
| `blueprint` | Blueprint identifier | true | |
| `scorecard` | Scorecard identifier | true | |
| `message_kind` | Message kind to send, to send Scorecard Report, pass - `scorecard_report` | true | |
| `filter_rule` | The [rule filter](https://docs.getport.io/search-and-query/#rules) to apply on the data queried from Port | false | |

```yaml
- uses: port-labs/[email protected]
with:
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
port_client_secret: ${{ secrets.PORT_CLIENT_SECRET }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
blueprint: app
scorecard: productionReadiness
message_kind: scorecard_report
```
## Send Scorecard Reminder
A call to action to remind the team that some of their services didn't reach Gold level for specific scorecard.
### example
![Scorecard Reminder](docs/assets/scorecard-reminder.png)
### Usage
| Input | Description | Required | Default |
| ----- |-------------------------------------------------------------------------------|----------| ------- |
| `port_client_id` | Port Client ID | true | |
| `port_client_secret` | Port Client Secret | true | |
| `slack_webhook_url` | Slack Webhook URL | true | |
| `blueprint` | Blueprint identifier | true | |
| `scorecard` | Scorecard identifier | true | |
| `message_kind` | Message kind to send, to send Scorecard Reminder, pass - `scorecard_reminder` | true | |
| `filter_rule` | The [rule filter](https://docs.getport.io/search-and-query/#rules) to apply on the data queried from Port | false | |

In this example you can see how we filter for specific team and send a reminder to them.

```yaml
- uses: port-labs/[email protected]
Expand All @@ -25,6 +68,6 @@ See [action.yml](action.yml) for inputs and outputs.
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
blueprint: service
scorecard: Ownership
message_kind: scorecard_report
message_kind: scorecard_reminder
filter_rule: '{"property": "$team","operator": "containsAny","value": ["Backend"]}'
```
Binary file added docs/assets/scorecard-reminder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
18 changes: 12 additions & 6 deletions generators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def scorecard_reminder(self,
blueprint: str,
scorecard: Dict[str, Any],
entities: list) -> List[Dict[str, Any]]:
blueprint_plural = utils.convert_to_plural(blueprint)
blueprint_plural = utils.convert_to_plural(blueprint).title()
entities_didnt_pass_gold_level = {
"Basic": [],
"Bronze": [],
"Silver": [],
"Bronze": [],
"Basic": [],
}
number_of_entities_didnt_pass_gold_level = 0
for entity in entities:
Expand All @@ -172,6 +172,11 @@ def scorecard_reminder(self,
)
number_of_entities_didnt_pass_gold_level += 1

entities_didnt_pass_gold_level_sorted = {
level: sorted(entities, key=lambda item: len(item.get("passed_rules", [])), reverse=True)
for level, entities in entities_didnt_pass_gold_level.items()
}

blocks = [
{
"type": "header",
Expand Down Expand Up @@ -200,7 +205,7 @@ def scorecard_reminder(self,
"text": {
"type": "mrkdwn",
"text": self._generate_entities_list_with_level_and_link(blueprint,
entities_didnt_pass_gold_level)
entities_didnt_pass_gold_level_sorted)
}
}
]
Expand Down Expand Up @@ -272,8 +277,9 @@ def _generate_entities_list_with_level_and_link(blueprint: str,
for level, entities in entities_by_level.items():
if not entities:
continue
text += f"*{level}*\n\n"

text += f"\n*{level}*\n\n"
for entity in entities:
text += f"• <{base_entity_url}{entity.get('identifier')}|{entity.get('name')}>" \
f" [{len(entity.get('passed_rules'))}/{entity.get('number_of_rules')}] Passed \n"
f" - `[{len(entity.get('passed_rules'))}/{entity.get('number_of_rules')}] Passed` \n"
return text

0 comments on commit be7bdc2

Please sign in to comment.