Skip to content

Commit

Permalink
Merge pull request #203 from Deuchnord/show-buildlabels-option
Browse files Browse the repository at this point in the history
Add an option to show the last build label
  • Loading branch information
anaynayak authored Jan 14, 2021
2 parents ad4b091 + 12ac8c9 commit 6465a2f
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 25 deletions.
9 changes: 9 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Local setup:

Paver commands can be viewed by running `paver -h`. Run `pip install paver` if not installed.

### Editig the UIs

To edit the dialog windows, you should use [Qt Designer](https://doc.qt.io/qt-5/qtdesigner-manual.html).
Once you're done, invoke the following command to regenerate its Python implementation:

```
pyuic5 -x data/<file>.ui -o buildnotifylib/generated/<file>_ui.py
```

### Packaging

Dependencies for creating a pip/deb package (use virtualenv)
Expand Down
2 changes: 1 addition & 1 deletion buildnotifylib/app_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def exit(self, widget: QWidget):
sys.exit()

def create_menu_item(self, project: Project, icon: QIcon):
menu_item_label = project.label()
menu_item_label = project.label(self.conf.get_show_last_build_label())
if self.conf.get_value("lastBuildTimeForProject"):
menu_item_label = menu_item_label + ", " + DistanceOfTime(project.get_last_build_time()).age() + " ago"

Expand Down
13 changes: 12 additions & 1 deletion buildnotifylib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

class Preferences(object):
def __init__(self, urls, interval, custom_script_text, custom_script_checked,
sort_by_build_time, sort_by_name, selections):
sort_by_build_time, sort_by_name, selections, show_last_build_label):
self.urls = urls
self.interval = interval
self.custom_script_text = custom_script_text
self.trigger_custom_script = custom_script_checked
self.sort_by_build_time = sort_by_build_time
self.sort_by_name = sort_by_name
self.selections = selections
self.show_last_build_label = show_last_build_label


class Config(object):
Expand All @@ -39,6 +40,8 @@ class Config(object):
VALUES = "values/%s"
NONE_TIMEZONE = "None"

SHOW_LAST_BUILD_LABEL = "show_last_build_label"

SORT_BY_LAST_BUILD_TIME = "sort_build_time"
SORT_BY_NAME = "sort_name"

Expand Down Expand Up @@ -126,6 +129,12 @@ def get_sort_by_name(self) -> bool:
return self.settings.value(self.SORT_KEY, self.SORT_BY_LAST_BUILD_TIME,
type=str) == self.SORT_BY_NAME

def get_show_last_build_label(self) -> bool:
return self.settings.value(self.SHOW_LAST_BUILD_LABEL, False, bool)

def set_show_last_build_label(self, show_last_build_label: bool):
self.settings.setValue(self.SHOW_LAST_BUILD_LABEL, show_last_build_label)

def set_sort_by_last_build_time(self):
self.settings.setValue(self.SORT_KEY, self.SORT_BY_LAST_BUILD_TIME)

Expand Down Expand Up @@ -189,6 +198,8 @@ def update_preferences(self, preferences: Preferences):
self.set_custom_script(preferences.custom_script_text,
preferences.trigger_custom_script)
self.set_custom_script_enabled(preferences.trigger_custom_script)
self.set_show_last_build_label(preferences.show_last_build_label)

if preferences.sort_by_build_time:
self.set_sort_by_last_build_time()
if preferences.sort_by_name:
Expand Down
11 changes: 8 additions & 3 deletions buildnotifylib/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ def __init__(self, server_url: str, prefix: str, timezone: str, props: Dict[str,
def get_build_status(self) -> str:
return self.status + "." + self.activity

def label(self) -> str:
def label(self, show_last_build_label: bool = False) -> str:
label = self.name

if self.prefix:
return "[" + self.prefix + "] " + self.name
return self.name
label = '[%s] %s' % (self.prefix, self.name)
if show_last_build_label:
label = '%s (%s)' % (label, self.last_build_label)

return label

def different_builds(self, project: 'Project') -> bool:
return self.last_build_label != project.last_build_label
Expand Down
19 changes: 12 additions & 7 deletions buildnotifylib/generated/preferences_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# Form implementation generated from reading ui file 'data/preferences.ui'
#
# Created by: PyQt5 UI code generator 5.13.1
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
Expand Down Expand Up @@ -127,6 +128,12 @@ def setupUi(self, Preferences):
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.gridLayout_5 = QtWidgets.QGridLayout()
self.gridLayout_5.setObjectName("gridLayout_5")
self.pollingIntervalLabel = QtWidgets.QLabel(self.miscTab)
self.pollingIntervalLabel.setObjectName("pollingIntervalLabel")
self.gridLayout_5.addWidget(self.pollingIntervalLabel, 4, 0, 1, 1)
self.showLastBuildLabelCheckbox = QtWidgets.QCheckBox(self.miscTab)
self.showLastBuildLabelCheckbox.setObjectName("showLastBuildLabelCheckbox")
self.gridLayout_5.addWidget(self.showLastBuildLabelCheckbox, 6, 1, 1, 1)
self.pollingIntervalSpinBox = QtWidgets.QSpinBox(self.miscTab)
self.pollingIntervalSpinBox.setMinimumSize(QtCore.QSize(130, 0))
self.pollingIntervalSpinBox.setMaximumSize(QtCore.QSize(130, 16777215))
Expand All @@ -136,9 +143,6 @@ def setupUi(self, Preferences):
self.pollingIntervalSpinBox.setSingleStep(1)
self.pollingIntervalSpinBox.setObjectName("pollingIntervalSpinBox")
self.gridLayout_5.addWidget(self.pollingIntervalSpinBox, 4, 1, 1, 1)
self.pollingIntervalLabel = QtWidgets.QLabel(self.miscTab)
self.pollingIntervalLabel.setObjectName("pollingIntervalLabel")
self.gridLayout_5.addWidget(self.pollingIntervalLabel, 4, 0, 1, 1)
self.showLastBuildTimeCheckbox = QtWidgets.QCheckBox(self.miscTab)
self.showLastBuildTimeCheckbox.setObjectName("showLastBuildTimeCheckbox")
self.gridLayout_5.addWidget(self.showLastBuildTimeCheckbox, 5, 1, 1, 1)
Expand All @@ -163,7 +167,7 @@ def setupUi(self, Preferences):
self.pollingIntervalLabel.setBuddy(self.pollingIntervalSpinBox)

self.retranslateUi(Preferences)
self.tabWidget.setCurrentIndex(0)
self.tabWidget.setCurrentIndex(2)
self.scriptCheckbox.toggled['bool'].connect(self.scriptLineEdit.setEnabled)
QtCore.QMetaObject.connectSlotsByName(Preferences)

Expand All @@ -188,8 +192,9 @@ def retranslateUi(self, Preferences):
self.scriptLabel.setText(_translate("Preferences", "Script"))
self.scriptLineEdit.setToolTip(_translate("Preferences", "#status# and #projects# would be replaced by the build status and projects respectively"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.notificationsTab), _translate("Preferences", "Notifications"))
self.pollingIntervalSpinBox.setSuffix(_translate("Preferences", " seconds"))
self.pollingIntervalLabel.setText(_translate("Preferences", "Server polling interval"))
self.showLastBuildLabelCheckbox.setText(_translate("Preferences", "show last build label for each project"))
self.pollingIntervalSpinBox.setSuffix(_translate("Preferences", " seconds"))
self.showLastBuildTimeCheckbox.setText(_translate("Preferences", "show last build time for each project"))
self.groupBox_4.setTitle(_translate("Preferences", "Build Sort order"))
self.sortBuildByName.setText(_translate("Preferences", "Sort builds by name"))
Expand Down
4 changes: 3 additions & 1 deletion buildnotifylib/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def set_values_from_config(self):
self.ui.scriptLineEdit.setText(self.conf.get_custom_script())
self.ui.sortBuildByLastBuildTime.setChecked(self.conf.get_sort_by_last_build_time())
self.ui.sortBuildByName.setChecked(self.conf.get_sort_by_name())
self.ui.showLastBuildLabelCheckbox.setChecked(self.conf.get_show_last_build_label())

def item_selection_changed(self, status):
self.ui.configureProjectButton.setEnabled(status)
Expand Down Expand Up @@ -86,6 +87,7 @@ def open(self) -> Optional[Preferences]: # type: ignore
custom_script_checked=self.ui.scriptCheckbox.isChecked(),
sort_by_build_time=self.ui.sortBuildByLastBuildTime.isChecked(),
sort_by_name=self.ui.sortBuildByName.isChecked(),
selections=self.get_selections()
selections=self.get_selections(),
show_last_build_label=self.ui.showLastBuildLabelCheckbox.isChecked()
)
return None
29 changes: 18 additions & 11 deletions data/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="serversTab">
<property name="sizePolicy">
Expand Down Expand Up @@ -249,6 +249,23 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_5">
<item row="4" column="0">
<widget class="QLabel" name="pollingIntervalLabel">
<property name="text">
<string>Server polling interval</string>
</property>
<property name="buddy">
<cstring>pollingIntervalSpinBox</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="showLastBuildLabelCheckbox">
<property name="text">
<string>show last build label for each project</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="pollingIntervalSpinBox">
<property name="minimumSize">
Expand Down Expand Up @@ -280,16 +297,6 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="pollingIntervalLabel">
<property name="text">
<string>Server polling interval</string>
</property>
<property name="buddy">
<cstring>pollingIntervalSpinBox</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="showLastBuildTimeCheckbox">
<property name="text">
Expand Down
3 changes: 2 additions & 1 deletion test/integration/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ def test_should_return_all_servers(self):
self.assertEqual('http://url2', servers[1].url)

def test_should_update_preferences(self):
self.config.update_preferences(Preferences(['url1'], 300, '/bin/sh', True, False, True, []))
self.config.update_preferences(Preferences(['url1'], 300, '/bin/sh', True, False, True, [], False))

self.assertEqual(self.config.get_urls(), ['url1'])
self.assertEqual(self.config.get_interval_in_seconds(), 300)
self.assertEqual(self.config.get_custom_script(), '/bin/sh')
self.assertEqual(self.config.get_custom_script_enabled(), True)
self.assertEqual(self.config.get_sort_by_last_build_time(), False)
self.assertEqual(self.config.get_sort_by_name(), True)
self.assertEqual(self.config.get_show_last_build_label(), False)


if __name__ == '__main__':
Expand Down
13 changes: 13 additions & 0 deletions test/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ def test_should_correctly_parse_project(self):
self.assertEqual(datetime.datetime(2009, 5, 29, 13, 54, 7, 0, tzlocal()), project.get_last_build_time())
self.assertEqual("Success.Sleeping", project.get_build_status())

def test_should_display_last_build_label_on_demand(self):
project = Project('url', None, 'None', {
'name': 'proj1',
'lastBuildStatus': 'Success',
'activity': 'Sleeping',
'url': '1.2.3.4:8080/cc.xml',
'lastBuildLabel': 'master',
'lastBuildTime': '2009-05-29T13:54:07'
})

self.assertEqual('proj1', project.label())
self.assertEqual('proj1 (master)', project.label(True))

def test_should_not_override_existing_url_scheme(self):
project = Project('url', '', 'tz', {
'name': 'proj1',
Expand Down

0 comments on commit 6465a2f

Please sign in to comment.