Skip to content

Commit

Permalink
Merge branch 'main' into fake_data
Browse files Browse the repository at this point in the history
  • Loading branch information
adhil0 authored Apr 15, 2024
2 parents 57e2cb3 + 6ce3a08 commit d1c9240
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 86 deletions.
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
repos:
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black

# isort
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black]

# flake8
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [--config=.github/linters/.flake8]

# gitleaks
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
hooks:
- id: gitleaks

# yamllint
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args: [-c=.github/linters/.yaml-lint.yml]

# prettier
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
types: [javascript]
32 changes: 27 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Some Common Ways to Contribute
# Contribution Guide

## Add a new page
## Pre-Commit

We have a `.pre-commit-config.yaml` file in our repository that will help you avoid common linting/formatting mistakes when you commit your changes. You can get set up by following
pre-commit's [quick start guide](https://pre-commit.com/#quick-start).

## Some Common Ways to Contribute

### Add a new page

The official Flask documentation contains a useful [walkthrough](https://flask.palletsprojects.com/en/3.0.x/quickstart/#rendering-templates) of how to add/modify a new web view.

Expand Down Expand Up @@ -48,7 +55,7 @@ You will be able to see your page by running your Flask server and visiting `<UR
Our templates are contained within `dashboard/src/t5gweb/templates` and our endpoints are
defined in `dashboard/src/t5gweb/ui.py`.

## Alter JavaScript
### Alter JavaScript

We are using a framework called [DataTables](https://datatables.net/) to add interactive tables to our dashboard. The majority of our JavaScript is related to these tables:

Expand Down Expand Up @@ -98,7 +105,7 @@ And that's it, we can now filter our table by "Case Status":

The DataTables [documentation](https://datatables.net) is very extensive, and can help you find and make any other changes that you might think of.

## Adding tests
### Adding tests

We use [pytest](https://docs.pytest.org/en/8.0.x/) for our unit tests. Pytest's docs are very helpful, but here's a simple example to get started:

Expand Down Expand Up @@ -178,7 +185,7 @@ In this case, the API call will not take place, and will instead be represented

Our unit tests are located in `tests/`, and we run tests automatically for PR's and commits on the `main` branch via GitHub Actions (`.github/workflows/linter.yml`). You can run tests locally by installing pytest and pytest-mock, and then running `pytest` from the root directory of the repository (`t5g-field-support-team-utils/`).

## Add a new scheduled task
### Add a new scheduled task

We use [Celery beat](https://docs.celeryq.dev/en/stable/userguide/periodic-tasks.html) to run our scheduled tasks, which gather data from various APIs and combine it into what is visible on our dashboard.

Expand All @@ -204,3 +211,18 @@ def setup_scheduled_tasks(sender, **kwargs):
```

Now, the message will be printed every 15 minutes.

### Common Debugging Techniques

To see how the DataTables framework parses your data, you can use the following snippet (adapted from DataTables [docs](https://datatables.net/reference/api/row().data()#Examples)):

```{javascript}
$(document).ready(function () {
...
$('#data tbody').on('click', 'tr', function () {
console.log(table.row(this).data());
});
...
```

This can be useful when setting up and modifying your table's configuration, especially with regards to searching and ordering.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Another volume is created for `/srv/t5gweb/static/node_modules/`. Without this v

If you want to add a new JS package, you'll need to add it to `package.json` and `package-lock.json` , which are located in `dashboard/src/t5gweb/static/`. Then you need to remove the relevant volume (`podman volume rm dashboard_dashboard-ui_<HASH>`) and rebuild the image.


Please see our [CONTRIBUTING.md](https://github.com/RHsyseng/t5g-field-support-team-utils/blob/main/CONTRIBUTING.md) for further development help.
## CI

This project has a CI that is triggered on every push.
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/t5gweb/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_cards(cfg, self=None, background=False):
},
)
issue = jira_conn.issue(card)
comments = jira_conn.comments(issue)
comments = issue.fields.comment.comments
card_comments = []
for comment in comments:
body = comment.body
Expand Down
35 changes: 30 additions & 5 deletions dashboard/src/t5gweb/libtelco5g.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ def create_cards(cfg, new_cases, action="none"):
"priority": {"name": priority},
"labels": cfg["labels"],
"summary": summary[:253] + ".." if len(summary) > 253 else summary,
"description": full_description[:253] + ".."
if len(full_description) > 253
else full_description,
"description": (
full_description[:253] + ".."
if len(full_description) > 253
else full_description
),
}

if assignee:
Expand Down Expand Up @@ -411,7 +413,7 @@ def get_case_from_link(jira_conn, card):
return None


def generate_stats(account=None):
def generate_stats(account=None, engineer=None):
"""generate some stats"""

logging.warning("generating stats")
Expand All @@ -426,6 +428,23 @@ def generate_stats(account=None):
logging.warning("filtering cases for {}".format(account))
cards = {c: d for (c, d) in cards.items() if d["account"] == account}
cases = {c: d for (c, d) in cases.items() if d["account"] == account}
if engineer is not None:
logging.warning("filtering cases for {}".format(engineer))
cards = {
c: d for (c, d) in cards.items() if d["assignee"]["displayName"] == engineer
}

# get case number and assignee from cards so that we can determine which cases
# belong to the engineer
temp_cases = {}
for case, details in cases.items():
for card in cards:
if (
case == cards[card]["case_number"]
and cards[card]["assignee"]["displayName"] == engineer
):
temp_cases[case] = details
cases = temp_cases

today = datetime.date.today()

Expand Down Expand Up @@ -602,7 +621,7 @@ def plot_stats():
return x_values, y_values


def generate_histogram_stats(account=None):
def generate_histogram_stats(account=None, engineer=None):
"""
Calculates histogram statistics for resolved and relief times of cards.
Expand Down Expand Up @@ -654,6 +673,12 @@ def generate_histogram_stats(account=None):
logging.warning(f"filtering cards for {account}")
cards = {c: d for (c, d) in cards.items() if d["account"] == account}

if engineer is not None:
logging.warning(f"filtering cards for {engineer}")
cards = {
c: d for (c, d) in cards.items() if d["assignee"]["displayName"] == engineer
}

histogram_data = {
"Resolved": base_dictionary,
"Relief": base_dictionary,
Expand Down
13 changes: 11 additions & 2 deletions dashboard/src/t5gweb/static/js/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ function format(data) {
result +=
'<h3>JIRA Issues:</h3><table class="table table-bordered table-hover table-responsive w-100"><thead><tr><th>#</th><th>Summary</th><th>Priority</th><th>Severity</th><th>Telco Priority</th><th>Target Release</th><th>Assignee</th><th>QA Contact</th><th>Last Updated</th><th>Status</th></tr></thead><tbody>';
for (let issue = 0; issue < data.issues.length; issue++) {
const telcoPriority =
data.issues[issue].private_keywords != null
? data.issues[issue].private_keywords.find((str) =>
str.includes("Priority"),
)
: null;
const priorityNum = telcoPriority
? telcoPriority.charAt(telcoPriority.length - 1)
: 0;
result +=
'<tr><td><a href="' +
data.issues[issue].url +
Expand All @@ -50,7 +59,7 @@ function format(data) {
(data.issues[issue].jira_severity != null
? data.issues[issue].jira_severity
: "---") +
"</td><td>" +
`</td><td class="telco-priority-${priorityNum}">` +
(data.issues[issue].private_keywords != null
? data.issues[issue].private_keywords.find((str) =>
str.includes("Priority"),
Expand Down Expand Up @@ -142,7 +151,7 @@ $(document).ready(function () {
label: "Cases on Prio-list or Watchlist or Crit Sit",
value: function (rowData, rowIdx) {
return (
rowData[3] === "Yes" ||
rowData[3].includes("Yes") ||
rowData[4] === "Yes" ||
rowData[5] === "Yes"
);
Expand Down
19 changes: 18 additions & 1 deletion dashboard/src/t5gweb/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,21 @@ span.anchor {
/* Makes sure Navbar doesn't cover content */
.new-cases {
padding-top: 70px;
}
}

/* Telco priority */
.telco-priority-1 {
color: red !important;
}

.telco-priority-2 {
color: orange !important;
}

.telco-priority-3 {
color: blue !important;
}

.telco-priority-4 {
color: black !important;
}
10 changes: 6 additions & 4 deletions dashboard/src/t5gweb/t5gweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ def get_new_cases():
return new_cases


def get_new_comments(new_comments_only=True, account=None):
def get_new_comments(cards, new_comments_only=True, account=None, engineer=None):
# fetch cards from redis cache
cards = libtelco5g.redis_get("cards")
if account is not None:
cards = {c: d for (c, d) in cards.items() if d["account"] == account}
if engineer is not None:
cards = {
c: d for (c, d) in cards.items() if d["assignee"]["displayName"] == engineer
}
logging.warning("found %d JIRA cards" % (len(cards)))
time_now = datetime.now(timezone.utc)

Expand Down Expand Up @@ -78,9 +81,8 @@ def get_new_comments(new_comments_only=True, account=None):
return accounts


def get_trending_cards():
def get_trending_cards(cards):
# fetch cards from redis cache
cards = libtelco5g.redis_get("cards")

# get a list of trending cards
trending_cards = [card for card in cards if "Trends" in cards[card]["labels"]]
Expand Down
12 changes: 6 additions & 6 deletions dashboard/src/t5gweb/templates/macros/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,24 @@ <h2>Statistics</h2>
</td>
{% if new_comments[account][status][card]['escalated'] %}
{% if new_comments[account][status][card]['escalated_link'] %}
<td class="align-middle text-center">
<td class="align-middle text-center fw-bold">
<a href="{{ new_comments[account][status][card]['escalated_link'] }}">Yes</a>
</td>
{% else %}
<td class="align-middle text-center">Yes</td>
<td class="align-middle text-center fw-bold">Yes</td>
{% endif %}
{% elif new_comments[account][status][card]['potential_escalation'] %}
<td class="align-middle text-center">Potentially</td>
<td class="align-middle text-center fw-bold">Potentially</td>
{% else %}
<td class="align-middle text-center">No</td>
{% endif %}
{% if new_comments[account][status][card]['watched'] %}
<td class="align-middle text-center">Yes</td>
<td class="align-middle text-center fw-bold">Yes</td>
{% else %}
<td class="align-middle text-center">No</td>
{% endif %}
{% if new_comments[account][status][card]['crit_sit'] %}
<td class="align-middle text-center">Yes</td>
<td class="align-middle text-center fw-bold">Yes</td>
{% else %}
<td class="align-middle text-center">No</td>
{% endif %}
Expand All @@ -138,7 +138,7 @@ <h2>Statistics</h2>
<td class="align-middle text-center">{{ new_comments[account][status][card]['case_status'] }}</td>
<td class="align-middle text-center">{{ new_comments[account][status][card]['card_status'] }}</td>
<td class="align-middle text-center">
{{ new_comments[account][status][card]['assignee']['displayName'] }}
<a href="{{ url_for('ui.get_engineer', engineer=new_comments[account][status][card]['assignee']['displayName']) }}">{{ new_comments[account][status][card]['assignee']['displayName'] }}</a>
{% if new_comments[account][status][card]['contributor'] | length %}
<br>
<br>
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/t5gweb/templates/ui/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
charset="utf8"
src="{{ url_for('static', filename='node_modules/plotly.js-cartesian-dist-min/plotly-cartesian.min.js') }}"></script>
<div class="container-fluid copy mt-5">
{% if engineer_view == True %}
<h2>Engineer Stats: {{ account }}</h2>
{% else %}
<h2>Account Stats: {{ account }}</h2>
{% endif %}
<div class="row">
<div class="col-sm-6">
<table class="table table-bordered table-hover table-responsive w-100"
Expand Down Expand Up @@ -179,6 +183,7 @@ <h2>Account Stats: {{ account }}</h2>
</div>
</div>
<br>
{% if engineer_view != True %}
<div class="bug-table">
<h2>Bugs and JIRA Issues:</h2>
<table class="table table-bordered table-hover table-responsive mt-5 w-100"
Expand Down Expand Up @@ -237,6 +242,7 @@ <h2>Bugs and JIRA Issues:</h2>
</tbody>
</table>
</div>
{% endif %}
<br>
<h2>Cases:</h2>
{{ macros.cases_table(new_comments, jira_server) }}
Expand Down
Loading

0 comments on commit d1c9240

Please sign in to comment.