From a139d79b403d95cf9d2039866121d820b54a70e0 Mon Sep 17 00:00:00 2001 From: Stan Manilov Date: Sat, 16 Oct 2021 16:42:55 +0300 Subject: [PATCH 01/20] Always start session on successful auth This results in automatic login after fingerprint is recognized. --- src/lightdm-gtk-greeter.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index cefa348f..519e9712 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -2589,13 +2589,7 @@ authentication_complete_cb (LightDMGreeter *ldm) if (lightdm_greeter_get_is_authenticated (ldm)) { - if (prompted) - start_session (); - else - { - gtk_widget_hide (GTK_WIDGET (password_entry)); - gtk_widget_grab_focus (GTK_WIDGET (user_combo)); - } + start_session (); } else { From 13582c6ead83fe4b273db0703366530b66b9efec Mon Sep 17 00:00:00 2001 From: Stan Manilov Date: Sun, 30 Jan 2022 13:34:28 +0200 Subject: [PATCH 02/20] Add configuration option for PAM autologin This allows the user to choose whether to login automatically once PAM succeeds for the selected user. On one hand, automatic login makes using fingerprint login more pleasant -- the user does not need to also press the "Log In" button, once the fingerprint is recognized. On the other hand, using different PAM methods, autologin might be undesirable, as scrolling through the list of users might login a selected user when it is undesired. For this reason, having this functionality as a user-configurable setting makes sense. --- data/lightdm-gtk-greeter.conf | 1 + src/greeterconfiguration.h | 1 + src/lightdm-gtk-greeter.c | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/data/lightdm-gtk-greeter.conf b/data/lightdm-gtk-greeter.conf index df961a82..052bf1d7 100644 --- a/data/lightdm-gtk-greeter.conf +++ b/data/lightdm-gtk-greeter.conf @@ -26,6 +26,7 @@ # position = x y ("50% 50%" by default) Login window position # default-user-image = Image used as default user icon, path or #icon-name # hide-user-image = false|true ("false" by default) +# pam-autologin = false|true ("false" by default) # # Panel: # panel-position = top|bottom ("top" by default) diff --git a/src/greeterconfiguration.h b/src/greeterconfiguration.h index 587226dc..4d81a077 100644 --- a/src/greeterconfiguration.h +++ b/src/greeterconfiguration.h @@ -29,6 +29,7 @@ #define CONFIG_KEY_RGBA "xft-rgba" #define CONFIG_KEY_HIDE_USER_IMAGE "hide-user-image" #define CONFIG_KEY_DEFAULT_USER_IMAGE "default-user-image" +#define CONFIG_KEY_PAM_AUTOLOGIN "pam-autologin" #define CONFIG_KEY_KEYBOARD "keyboard" #define CONFIG_KEY_READER "reader" #define CONFIG_KEY_CLOCK_FORMAT "clock-format" diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 519e9712..03deb8e8 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -2589,7 +2589,17 @@ authentication_complete_cb (LightDMGreeter *ldm) if (lightdm_greeter_get_is_authenticated (ldm)) { + if (config_get_bool (NULL, CONFIG_KEY_PAM_AUTOLOGIN, FALSE)) { start_session (); + } else { + if (prompted) + start_session (); + else + { + gtk_widget_hide (GTK_WIDGET (password_entry)); + gtk_widget_grab_focus (GTK_WIDGET (user_combo)); + } + } } else { From 9a70526ecf903af7c5ac1c45aea944dfdc05b900 Mon Sep 17 00:00:00 2001 From: Stan Manilov Date: Sun, 30 Jan 2022 14:48:05 +0200 Subject: [PATCH 03/20] Add comment about the purpose of pam-autologin --- data/lightdm-gtk-greeter.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/lightdm-gtk-greeter.conf b/data/lightdm-gtk-greeter.conf index 052bf1d7..b8670953 100644 --- a/data/lightdm-gtk-greeter.conf +++ b/data/lightdm-gtk-greeter.conf @@ -26,7 +26,8 @@ # position = x y ("50% 50%" by default) Login window position # default-user-image = Image used as default user icon, path or #icon-name # hide-user-image = false|true ("false" by default) -# pam-autologin = false|true ("false" by default) +# pam-autologin = false|true ("false" by default) Whether the currently selected user should be logged in automatically, once a PAM auth succeeds. +# # # Panel: # panel-position = top|bottom ("top" by default) From f48d74bc15b9bba6edd09a731fce3c8bdee3056f Mon Sep 17 00:00:00 2001 From: Stan Manilov Date: Sun, 30 Jan 2022 15:01:21 +0200 Subject: [PATCH 04/20] Fix indentation The indentation I used earlier was 2 spaces, while the file uses 4 spaces elsewhere. Although this makes the diff harder to read, it makes the code consistent. --- src/lightdm-gtk-greeter.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 4f58fa7d..7a5648e3 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -2569,17 +2569,17 @@ authentication_complete_cb (LightDMGreeter *ldm) if (lightdm_greeter_get_is_authenticated (ldm)) { - if (config_get_bool (NULL, CONFIG_KEY_PAM_AUTOLOGIN, FALSE)) { - start_session (); - } else { - if (prompted) + if (config_get_bool (NULL, CONFIG_KEY_PAM_AUTOLOGIN, FALSE)) { start_session (); - else - { - gtk_widget_hide (GTK_WIDGET (password_entry)); - gtk_widget_grab_focus (GTK_WIDGET (user_combo)); + } else { + if (prompted) + start_session (); + else + { + gtk_widget_hide (GTK_WIDGET (password_entry)); + gtk_widget_grab_focus (GTK_WIDGET (user_combo)); + } } - } } else { From 7b0a6377da69a6e8240550ec2b73593cd421d1f3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Apr 2022 15:26:10 +0000 Subject: [PATCH 05/20] Bump actions/setup-python from 2 to 3.1.1 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3.1.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v2...v3.1.1) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/track-lp-issues.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/track-lp-issues.yaml b/.github/workflows/track-lp-issues.yaml index 94d64327..910d8a7e 100644 --- a/.github/workflows/track-lp-issues.yaml +++ b/.github/workflows/track-lp-issues.yaml @@ -18,7 +18,7 @@ jobs: # Checkout code - uses: actions/checkout@v2 - name: Install Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3.1.1 with: python-version: 3.6 - name: Install dependencies From 887c664c2d4e3cee313aec831c7cd58c561928f7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 15:15:54 +0000 Subject: [PATCH 06/20] Bump actions/checkout from 2 to 3.0.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.0.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3.0.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/distcheck.yml | 2 +- .github/workflows/track-lp-issues.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/distcheck.yml b/.github/workflows/distcheck.yml index 6d0f95f4..0794d281 100644 --- a/.github/workflows/distcheck.yml +++ b/.github/workflows/distcheck.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.0.2 - name: apt update run: sudo apt update - name: Install build dependencies diff --git a/.github/workflows/track-lp-issues.yaml b/.github/workflows/track-lp-issues.yaml index 910d8a7e..fe6fd8ec 100644 --- a/.github/workflows/track-lp-issues.yaml +++ b/.github/workflows/track-lp-issues.yaml @@ -16,7 +16,7 @@ jobs: steps: # Checkout code - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.0.2 - name: Install Python 3 uses: actions/setup-python@v3.1.1 with: From b98e0afdb8c29a780e5659a29df5b236da24734e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 May 2022 15:09:11 +0000 Subject: [PATCH 07/20] Bump actions/setup-python from 3.1.1 to 3.1.2 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.1 to 3.1.2. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v3.1.1...v3.1.2) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/track-lp-issues.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/track-lp-issues.yaml b/.github/workflows/track-lp-issues.yaml index fe6fd8ec..974d20ee 100644 --- a/.github/workflows/track-lp-issues.yaml +++ b/.github/workflows/track-lp-issues.yaml @@ -18,7 +18,7 @@ jobs: # Checkout code - uses: actions/checkout@v3.0.2 - name: Install Python 3 - uses: actions/setup-python@v3.1.1 + uses: actions/setup-python@v3.1.2 with: python-version: 3.6 - name: Install dependencies From 66a138edb643efc5990f659ff21dd3897c64c077 Mon Sep 17 00:00:00 2001 From: Arialdo Martini Date: Tue, 17 May 2022 07:10:14 +0200 Subject: [PATCH 08/20] typo: it's => its --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5de4fd83..968a4c35 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ LightDM configuration is provided by the following files: /etc/lightdm/lightdm.conf ``` -**LightDM GTK Greeter uses `lightdm-gtk-greeter.conf` for it's configuration.** +**LightDM GTK Greeter uses `lightdm-gtk-greeter.conf` for its configuration.** System provided configuration should be stored in `/usr/share/lightdm/lightdm.conf.d/`. System administrators can override this configuration by adding files to `/etc/lightdm/lightdm.conf.d/` and `/etc/lightdm/lightdm.conf`. Files are read in the above order and combined together to make the LightDM configuration. From e18270b117174247651226f7ecdf6e5558b8ac39 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Jun 2022 15:14:16 +0000 Subject: [PATCH 09/20] Bump actions/setup-python from 3.1.2 to 4.0.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.2 to 4.0.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v3.1.2...v4.0.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/track-lp-issues.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/track-lp-issues.yaml b/.github/workflows/track-lp-issues.yaml index 974d20ee..0633b9de 100644 --- a/.github/workflows/track-lp-issues.yaml +++ b/.github/workflows/track-lp-issues.yaml @@ -18,7 +18,7 @@ jobs: # Checkout code - uses: actions/checkout@v3.0.2 - name: Install Python 3 - uses: actions/setup-python@v3.1.2 + uses: actions/setup-python@v4.0.0 with: python-version: 3.6 - name: Install dependencies From f9c31348fa0c64f0b479c1ee8d29e5c6c6154cb8 Mon Sep 17 00:00:00 2001 From: Konrad Bucheli Date: Mon, 25 Jul 2022 15:05:18 +0200 Subject: [PATCH 10/20] allow to configure a default session manager --- data/lightdm-gtk-greeter.conf | 3 +++ src/greeterconfiguration.h | 1 + src/lightdm-gtk-greeter.c | 29 +++++++++++++++++++---------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/data/lightdm-gtk-greeter.conf b/data/lightdm-gtk-greeter.conf index ab1ba1ab..48d26d32 100644 --- a/data/lightdm-gtk-greeter.conf +++ b/data/lightdm-gtk-greeter.conf @@ -46,6 +46,9 @@ # allow-debugging = false|true ("false" by default) # screensaver-timeout = Timeout (in seconds) until the screen blanks when the greeter is called as lockscreen # +# Session: +# default-session = session manager to be started when none has been selected by the user and no one is set as last used (unset by default) +# # Template for per-monitor configuration: # [monitor: name] # background = overrides default value diff --git a/src/greeterconfiguration.h b/src/greeterconfiguration.h index 89146c53..2f193c90 100644 --- a/src/greeterconfiguration.h +++ b/src/greeterconfiguration.h @@ -16,6 +16,7 @@ #define CONFIG_GROUP_DEFAULT "greeter" #define CONFIG_KEY_INDICATORS "indicators" +#define CONFIG_KEY_DEFAULT_SESSION "default-session" #define CONFIG_KEY_DEBUGGING "allow-debugging" #define CONFIG_KEY_SCREENSAVER_TIMEOUT "screensaver-timeout" #define CONFIG_KEY_THEME "theme-name" diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 7a5648e3..d0e7254f 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -1002,6 +1002,7 @@ static void set_session (const gchar *session) { gchar *last_session = NULL; + gchar *greeter_default_session = NULL; GList *sessions = lightdm_get_sessions (); /* Validation */ @@ -1015,16 +1016,23 @@ set_session (const gchar *session) else { /* default */ - const gchar* default_session = lightdm_greeter_get_default_session_hint (greeter); - if (g_strcmp0 (session, default_session) != 0 && - is_valid_session (sessions, default_session)) - session = default_session; - /* first in the sessions list */ - else if (sessions) - session = lightdm_session_get_key (sessions->data); - /* give up */ + greeter_default_session = config_get_string (NULL, CONFIG_KEY_DEFAULT_SESSION, NULL); + if (greeter_default_session && g_strcmp0 (session, greeter_default_session) != 0 && + is_valid_session (sessions, greeter_default_session)) + session = greeter_default_session; else - session = NULL; + { + const gchar* default_session = lightdm_greeter_get_default_session_hint (greeter); + if (g_strcmp0 (session, default_session) != 0 && + is_valid_session (sessions, default_session)) + session = default_session; + /* first in the sessions list */ + else if (sessions) + session = lightdm_session_get_key (sessions->data); + /* give up */ + else + session = NULL; + } } } @@ -1060,6 +1068,7 @@ set_session (const gchar *session) g_free (current_session); current_session = g_strdup (session); g_free (last_session); + g_free (greeter_default_session); } void @@ -2390,7 +2399,7 @@ set_displayed_user (LightDMGreeter *ldm, const gchar *username) else { set_language (lightdm_language_get_code (lightdm_get_language ())); - set_session (lightdm_greeter_get_default_session_hint (ldm)); + set_session (NULL); } gtk_widget_set_tooltip_text (GTK_WIDGET (user_combo), user_tooltip); start_authentication (username); From 0c901da6dfb4dcfc9fe14afd6bf18524336472f2 Mon Sep 17 00:00:00 2001 From: Konrad Bucheli Date: Wed, 20 Jul 2022 13:18:23 +0200 Subject: [PATCH 11/20] support configuring the keyboard layouts of the ~layout indicator --- data/lightdm-gtk-greeter.conf | 3 ++- src/greeterconfiguration.h | 1 + src/lightdm-gtk-greeter.c | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/data/lightdm-gtk-greeter.conf b/data/lightdm-gtk-greeter.conf index 48d26d32..aac11fde 100644 --- a/data/lightdm-gtk-greeter.conf +++ b/data/lightdm-gtk-greeter.conf @@ -33,7 +33,8 @@ # Panel: # panel-position = top|bottom ("top" by default) # clock-format = strftime-format string, e.g. %H:%M -# indicators = semi-colon ";" separated list of allowed indicator modules. Built-in indicators include "~a11y", "~language", "~session", "~power", "~clock", "~host", "~spacer". Unity indicators can be represented by short name (e.g. "sound", "power"), service file name, or absolute path +# indicators = semi-colon ";" separated list of allowed indicator modules. Built-in indicators include "~a11y", "~language", "~session", "~power", "~clock", "~host", "~spacer", "~layout". Unity indicators can be represented by short name (e.g. "sound", "power"), service file name, or absolute path +# keyboard-layouts = semi-colon ";" separated list keyboard layouts to be listed by the "~layout" indicator (empty by default which provides all available layouts) # # Accessibility: # a11y-states = states of accessibility features: "name" - save state on exit, "-name" - disabled at start (default value for unlisted), "+name" - enabled at start. Allowed names: contrast, font, keyboard, reader. diff --git a/src/greeterconfiguration.h b/src/greeterconfiguration.h index 2f193c90..7377b45b 100644 --- a/src/greeterconfiguration.h +++ b/src/greeterconfiguration.h @@ -34,6 +34,7 @@ #define CONFIG_KEY_HIGHLIGHT_LOGGED_USER "highlight-logged-user" #define CONFIG_KEY_PAM_AUTOLOGIN "pam-autologin" #define CONFIG_KEY_KEYBOARD "keyboard" +#define CONFIG_KEY_KEYBOARD_LAYOUTS "keyboard-layouts" #define CONFIG_KEY_READER "reader" #define CONFIG_KEY_CLOCK_FORMAT "clock-format" #define CONFIG_KEY_ACTIVE_MONITOR "active-monitor" diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index d0e7254f..bb0d03cc 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -1764,6 +1764,13 @@ layout_selected_cb (GtkCheckMenuItem *menuitem, gpointer user_data) static void update_layouts_menu (void) { + gchar **layouts; + gsize num_layouts = 0; + + layouts = config_get_string_list (NULL, CONFIG_KEY_KEYBOARD_LAYOUTS, NULL); + if (layouts) + num_layouts = g_strv_length (layouts); + #ifdef HAVE_LIBXKLAVIER XklConfigRegistry *registry; XklConfigRec *config; @@ -1792,6 +1799,23 @@ update_layouts_menu (void) const gchar *variant = config->variants[i] ? config->variants[i] : ""; gchar *label = strlen (variant) > 0 ? g_strdup_printf ("%s_%s", layout, variant) : g_strdup (layout); + /* is the keyboard layout part of keyboard-layouts? */ + if (num_layouts) { + gboolean layout_in_config = FALSE; + for (gint j = 0; j < num_layouts; ++j) + { + if (g_strcmp0 (layouts[j], label) == 0) + { + layout_in_config = TRUE; + break; + } + } + if (!layout_in_config) { + g_free(label); + continue; + } + } + GtkWidget *menuitem = gtk_radio_menu_item_new (menu_group); menu_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); @@ -1828,6 +1852,23 @@ update_layouts_menu (void) for (item = lightdm_get_layouts (); item; item = g_list_next (item)) { LightDMLayout *layout = item->data; + + /* is the keyboard layout part of keyboard-layouts? */ + if (num_layouts) { + gboolean layout_in_config = FALSE; + for (gint j = 0; j < num_layouts; ++j) + { + if (g_strcmp0 (layouts[j], lightdm_layout_get_name (layout)) == 0) + { + layout_in_config = TRUE; + break; + } + } + if (!layout_in_config) { + continue; + } + } + GtkWidget *menuitem = gtk_radio_menu_item_new (menu_group); menu_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); @@ -1842,6 +1883,9 @@ update_layouts_menu (void) gtk_widget_show (GTK_WIDGET (menuitem)); } #endif + + if (layouts) + g_strfreev (layouts); } static void From d57db8966ed40353988e4e76442f62973e3640ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 15:22:43 +0000 Subject: [PATCH 12/20] Bump actions/setup-python from 4.0.0 to 4.1.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.0.0 to 4.1.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.0.0...v4.1.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/track-lp-issues.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/track-lp-issues.yaml b/.github/workflows/track-lp-issues.yaml index 0633b9de..5a40e72c 100644 --- a/.github/workflows/track-lp-issues.yaml +++ b/.github/workflows/track-lp-issues.yaml @@ -18,7 +18,7 @@ jobs: # Checkout code - uses: actions/checkout@v3.0.2 - name: Install Python 3 - uses: actions/setup-python@v4.0.0 + uses: actions/setup-python@v4.1.0 with: python-version: 3.6 - name: Install dependencies From 1ad88e20a064c7d482d2fbc00796b8d97afc1433 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Aug 2022 15:13:16 +0000 Subject: [PATCH 13/20] Bump actions/setup-python from 4.1.0 to 4.2.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.1.0 to 4.2.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.1.0...v4.2.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/track-lp-issues.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/track-lp-issues.yaml b/.github/workflows/track-lp-issues.yaml index 5a40e72c..11917c29 100644 --- a/.github/workflows/track-lp-issues.yaml +++ b/.github/workflows/track-lp-issues.yaml @@ -18,7 +18,7 @@ jobs: # Checkout code - uses: actions/checkout@v3.0.2 - name: Install Python 3 - uses: actions/setup-python@v4.1.0 + uses: actions/setup-python@v4.2.0 with: python-version: 3.6 - name: Install dependencies From bff8344b34d1b2d8656a0a41a1b288a010c03c9e Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:41:18 +0000 Subject: [PATCH 14/20] Fix exit condition --- autogen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen.sh b/autogen.sh index 973fb985..eeccce2d 100755 --- a/autogen.sh +++ b/autogen.sh @@ -50,7 +50,7 @@ cd "$olddir" if [ "$NOCONFIGURE" = "" ]; then $srcdir/configure "$@" || exit 1 - if [ "$1" = "--help" ]; then exit 0 else + if [ "$1" = "--help" ]; then exit 0; else echo "Now type 'make' to compile $PKG_NAME" || exit 1 fi else From 0b0cbce3b3b6003f7f3e6d8e20fe151426691de9 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Sat, 27 Aug 2022 13:55:10 +0000 Subject: [PATCH 15/20] Fix typos --- src/greeterbackground.c | 2 +- src/lightdm-gtk-greeter.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/greeterbackground.c b/src/greeterbackground.c index 9a33b6b9..b1666d89 100644 --- a/src/greeterbackground.c +++ b/src/greeterbackground.c @@ -747,7 +747,7 @@ greeter_background_set_active_monitor(GreeterBackground* background, if (priv->active_monitor_change_in_progress) return; - /* Prevents infinite signal emmission between two monitors (LP: #1410406, #1509780) + /* Prevents infinite signal emission between two monitors (LP: #1410406, #1509780) * There are some rare scenarios when using multiple monitors that cause the greeter * to switch back and forth between the monitors indefinitely. By comparing the * timestamp at this precision (1/10th of a second), this should no longer be diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index bb0d03cc..2318dd5f 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -198,7 +198,7 @@ static gchar* get_session (void); static void set_session (const gchar *session); void session_selected_cb (GtkMenuItem *menuitem, gpointer user_data); -/* Sesion language */ +/* Session language */ static gchar *current_language; static gchar* get_language (void); static void set_language (const gchar *language); @@ -1962,7 +1962,7 @@ xkl_xevent_filter (GdkXEvent *xev, GdkEvent *event, gpointer data) } #endif -/* a11y indciator */ +/* a11y indicator */ void a11y_font_cb (GtkCheckMenuItem *item) @@ -2904,7 +2904,7 @@ main (int argc, char **argv) out to relieve memory pressure." With systemd version 239 the ulimit for RLIMIT_MEMLOCK was set to 16 MiB - and therefore the mlockall call would fail. This is lucky becasue the subsequent mmap would not fail. + and therefore the mlockall call would fail. This is lucky because the subsequent mmap would not fail. With systemd version 240 the RLIMIT_MEMLOCK is now set to 64 MiB and now the mlockall no longer fails. However, it not possible to mmap in all From b8c47245c2bfd3708b39f74dcd2a896cb6a793ce Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:26:28 +0000 Subject: [PATCH 16/20] Use https links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 968a4c35..3aca3845 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ Configuration is in keyfile format. For most installations you will want to chan ## Questions -Questions about LightDM and LightDM GTK Greeter should be asked on the [mailing list](http://lists.freedesktop.org/mailman/listinfo/lightdm). All questions are welcome. +Questions about LightDM and LightDM GTK Greeter should be asked on the [mailing list](https://lists.freedesktop.org/mailman/listinfo/lightdm). All questions are welcome. -[Stack Overflow](http://stackoverflow.com/search?q=lightdm) and [Ask Ubuntu](http://askubuntu.com/search?q=lightdm) are good sites for frequently asked questions. +[Stack Overflow](https://stackoverflow.com/search?q=lightdm) and [Ask Ubuntu](https://askubuntu.com/search?q=lightdm) are good sites for frequently asked questions. ## Links - [Homepage](https://github.com/xubuntu/lightdm-gtk-greeter) From b63adf1558f8c36f8bb69bbcce8f5121f075e10d Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:19:16 +0000 Subject: [PATCH 17/20] Use license file from gnu.org File downloaded from: https://www.gnu.org/licenses/gpl-3.0.txt --- COPYING | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/COPYING b/COPYING index 94a9ed02..f288702d 100644 --- a/COPYING +++ b/COPYING @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. From 2e6f101f828d69ca541ca08cd5bc5b2e45b1df9c Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:01:30 +0000 Subject: [PATCH 18/20] Stop mixing tabs and spaces --- README.md | 1 - data/sample-lightdm-gtk-greeter.css | 6 +++--- src/greeter_menu_bar.xml | 4 ++-- src/greeterbackground.c | 16 +++++++-------- src/greetermenubar.c | 32 ++++++++++++++--------------- src/greetermenubar.h | 4 ++-- src/lightdm-gtk-greeter.c | 28 ++++++++++++------------- 7 files changed, 45 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 3aca3845..81628176 100644 --- a/README.md +++ b/README.md @@ -55,4 +55,3 @@ Questions about LightDM and LightDM GTK Greeter should be asked on the [mailing - [Releases](https://github.com/xubuntu/lightdm-gtk-greeter/releases) - [Bug Reports](https://github.com/xubuntu/lightdm-gtk-greeter/issues) - [Translations](https://www.transifex.com/xubuntu/lightdm-gtk-greeter) - diff --git a/data/sample-lightdm-gtk-greeter.css b/data/sample-lightdm-gtk-greeter.css index 1ef1c387..42b125f6 100644 --- a/data/sample-lightdm-gtk-greeter.css +++ b/data/sample-lightdm-gtk-greeter.css @@ -19,7 +19,7 @@ For more fine-grain control, you can also use the named widgets. Those are being /************************* * 2. Advanced theme * *************************/ - + /* the panel widget at the top */ #panel_window { background-color: alpha (black, 0.5); @@ -89,7 +89,7 @@ For more fine-grain control, you can also use the named widgets. Those are being #login_window GtkComboBox .button:active:hover:focus { padding: 0; background: none; - border-style: none; + border-style: none; box-shadow: none; } @@ -130,7 +130,7 @@ For more fine-grain control, you can also use the named widgets. Those are being ); color: @lightdm_fg_color; - + box-shadow: none; transition: all 150ms ease-out; } diff --git a/src/greeter_menu_bar.xml b/src/greeter_menu_bar.xml index a009c1a5..aa3d3783 100644 --- a/src/greeter_menu_bar.xml +++ b/src/greeter_menu_bar.xml @@ -1,7 +1,7 @@ - - diff --git a/src/greeterbackground.c b/src/greeterbackground.c index b1666d89..a3da1351 100644 --- a/src/greeterbackground.c +++ b/src/greeterbackground.c @@ -139,13 +139,13 @@ static const Monitor INVALID_MONITOR_STRUCT = {0}; struct _GreeterBackground { - GObject parent_instance; - struct _GreeterBackgroundPrivate* priv; + GObject parent_instance; + struct _GreeterBackgroundPrivate* priv; }; struct _GreeterBackgroundClass { - GObjectClass parent_class; + GObjectClass parent_class; }; typedef struct _GreeterBackgroundPrivate GreeterBackgroundPrivate; @@ -166,11 +166,11 @@ struct _GreeterBackgroundPrivate /* Default config for unlisted monitors */ MonitorConfig* default_config; - /* Array of configured monitors for current screen */ + /* Array of configured monitors for current screen */ Monitor* monitors; gsize monitors_size; - /* Name => , "Number" => */ + /* Name => , "Number" => */ GHashTable* monitors_map; GList* active_monitors_config; @@ -327,7 +327,7 @@ static const MonitorConfig DEFAULT_MONITOR_CONFIG = static void greeter_background_class_init(GreeterBackgroundClass* klass) { - GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); background_signals[BACKGROUND_SIGNAL_ACTIVE_MONITOR_CHANGED] = g_signal_new("active-monitor-changed", @@ -376,7 +376,7 @@ greeter_background_new(GtkWidget* child) background = GREETER_BACKGROUND(g_object_new(greeter_background_get_type(), NULL)); background->priv->child = child; g_signal_connect(background->priv->child, "destroy", G_CALLBACK(greeter_background_child_destroyed_cb), background); - return background; + return background; } void @@ -643,7 +643,7 @@ greeter_background_connect(GreeterBackground* background, monitor_set_background(monitor, bg); background_unref(&bg); } - else + else monitor_set_background(monitor, monitor->background_configured); if(monitor->name) diff --git a/src/greetermenubar.c b/src/greetermenubar.c index 31e60410..6aa7136e 100644 --- a/src/greetermenubar.c +++ b/src/greetermenubar.c @@ -19,8 +19,8 @@ G_DEFINE_TYPE(GreeterMenuBar, greeter_menu_bar, GTK_TYPE_MENU_BAR); static void greeter_menu_bar_class_init(GreeterMenuBarClass* klass) { - GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass); - widget_class->size_allocate = greeter_menu_bar_size_allocate; + GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass); + widget_class->size_allocate = greeter_menu_bar_size_allocate; } static void @@ -32,7 +32,7 @@ greeter_menu_bar_init(GreeterMenuBar* square) GtkWidget* greeter_menu_bar_new(void) { - return GTK_WIDGET(g_object_new(greeter_menu_bar_get_type(), NULL)); + return GTK_WIDGET(g_object_new(greeter_menu_bar_get_type(), NULL)); } static gint @@ -46,15 +46,15 @@ sort_minimal_size(gconstpointer a, gconstpointer b, GtkRequestedSize* sizes) static void greeter_menu_bar_size_allocate(GtkWidget* widget, GtkAllocation* allocation) { - GtkPackDirection pack_direction; - GList *item; - GList *shell_children; - GList *expand_nums = NULL; - guint visible_count = 0; - guint expand_count = 0; + GtkPackDirection pack_direction; + GList *item; + GList *shell_children; + GList *expand_nums = NULL; + guint visible_count = 0; + guint expand_count = 0; - g_return_if_fail(allocation != NULL); - g_return_if_fail(GREETER_IS_MENU_BAR(widget)); + g_return_if_fail(allocation != NULL); + g_return_if_fail(GREETER_IS_MENU_BAR(widget)); gtk_widget_set_allocation(widget, allocation); @@ -89,9 +89,9 @@ greeter_menu_bar_size_allocate(GtkWidget* widget, GtkAllocation* allocation) GtkShadowType shadow_type = GTK_SHADOW_OUT; GtkBorder border; gint toggle_size; - GtkRequestedSize* request; - gboolean ltr; - int size; + GtkRequestedSize* request; + gboolean ltr; + int size; gtk_style_context_get_padding(context, flags, &border); gtk_widget_style_get(widget, "shadow-type", &shadow_type, NULL); @@ -142,7 +142,7 @@ greeter_menu_bar_size_allocate(GtkWidget* widget, GtkAllocation* allocation) /* Distribution extra space for widgets with expand=True */ if(size > 0 && expand_nums) { - GList *first_item = NULL; + GList *first_item = NULL; gint needed_size = -1; gint max_size = 0; gint total_needed_size = 0; @@ -177,7 +177,7 @@ greeter_menu_bar_size_allocate(GtkWidget* widget, GtkAllocation* allocation) for(item = first_item; item; item = g_list_next(item)) { - gint dsize = 0; + gint dsize = 0; request = &requested_sizes[GPOINTER_TO_INT(item->data)]; dsize = needed_size - request->natural_size; diff --git a/src/greetermenubar.h b/src/greetermenubar.h index 333aff97..feb48a22 100644 --- a/src/greetermenubar.h +++ b/src/greetermenubar.h @@ -27,12 +27,12 @@ typedef struct _GreeterMenuBarClass GreeterMenuBarClass; struct _GreeterMenuBar { - GtkMenuBar parent_instance; + GtkMenuBar parent_instance; }; struct _GreeterMenuBarClass { - GtkMenuBarClass parent_class; + GtkMenuBarClass parent_class; }; GType greeter_menu_bar_get_type(void) G_GNUC_CONST; diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 2318dd5f..6237bcc2 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -1062,7 +1062,7 @@ set_session (const gchar *session) menu_iter = menu_items; if (menu_iter) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_iter->data), TRUE); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_iter->data), TRUE); } g_free (current_session); @@ -2152,19 +2152,19 @@ start_authentication (const gchar *username) lightdm_greeter_authenticate (greeter, NULL); #endif - if (lightdm_greeter_get_lock_hint (greeter)) - { - GList * items = lightdm_user_list_get_users (lightdm_user_list_get_instance ()); - for (GList * item = items; item; item = item->next) - { - LightDMUser *user = item->data; - if( lightdm_user_get_logged_in (user)) - { - gtk_entry_set_text (username_entry,lightdm_user_get_name(user)); - break; - } - } - } + if (lightdm_greeter_get_lock_hint (greeter)) + { + GList * items = lightdm_user_list_get_users (lightdm_user_list_get_instance ()); + for (GList * item = items; item; item = item->next) + { + LightDMUser *user = item->data; + if( lightdm_user_get_logged_in (user)) + { + gtk_entry_set_text (username_entry,lightdm_user_get_name(user)); + break; + } + } + } } else if (g_strcmp0 (username, "*guest") == 0) { From 3497bcf04e8d44aa38ac6896a6df08702f0f9a07 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:01:20 +0000 Subject: [PATCH 19/20] Add missing final newline --- data/sample-lightdm-gtk-greeter.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/sample-lightdm-gtk-greeter.css b/data/sample-lightdm-gtk-greeter.css index 42b125f6..2edf6393 100644 --- a/data/sample-lightdm-gtk-greeter.css +++ b/data/sample-lightdm-gtk-greeter.css @@ -282,4 +282,4 @@ For more fine-grain control, you can also use the named widgets. Those are being #greeter_infobar { border-bottom-width: 0; font: bold; -} \ No newline at end of file +} From b1b03f4f7000e8c3b8a9ea7185a5e468748fce67 Mon Sep 17 00:00:00 2001 From: Sean Davis Date: Sun, 18 Sep 2022 08:18:06 -0400 Subject: [PATCH 20/20] Sync extended bug details from Launchpad --- .github/lpbugtracker.py | 295 ++++++++++++++++++++++++++++++++++------ 1 file changed, 250 insertions(+), 45 deletions(-) diff --git a/.github/lpbugtracker.py b/.github/lpbugtracker.py index 880bbce9..4ccd6f0f 100755 --- a/.github/lpbugtracker.py +++ b/.github/lpbugtracker.py @@ -10,6 +10,8 @@ import os import subprocess import logging +import json + from launchpadlib.launchpad import Launchpad log = logging.getLogger("lpbugtracker") @@ -24,6 +26,18 @@ HOME = os.path.expanduser("~") CACHEDIR = os.path.join(HOME, ".launchpadlib", "cache") +LP_OPEN_STATUS_LIST = ["New", + "Opinion", + "Confirmed", + "Triaged", + "In Progress", + "Fix Committed", + "Incomplete"] +LP_CLOSED_STATUS_LIST = ["Invalid", + "Won't Fix", + "Expired", + "Fix Released"] + def main(): lp_bugs = get_lp_bugs() @@ -34,15 +48,143 @@ def main(): for id in lp_bugs: if id in gh_bugs.keys(): + last_comment_id = get_gh_last_lp_comment(gh_bugs[id]["id"]) + add_comments(gh_bugs[id]["id"], last_comment_id, lp_bugs[id]["messages"]) + + gh_labels = parse_gh_labels(gh_bugs[id]["labels"]) if lp_bugs[id]["closed"] and gh_bugs[id]["status"] != "closed": - close_issue(gh_bugs[id]["id"], lp_bugs[id]["status"]) + close_issue(gh_bugs[id]["id"], gh_labels["labels"], lp_bugs[id]["status"]) + elif lp_bugs[id]["status"] != gh_labels["status"]: + update_issue(gh_bugs[id]["id"], gh_labels["labels"], lp_bugs[id]["status"]) elif not lp_bugs[id]["closed"] and lp_bugs[id]["status"] != "Incomplete": - create_issue(id, lp_bugs[id]["title"], lp_bugs[id]["link"]) + bug_id = create_issue(id, lp_bugs[id]["title"], lp_bugs[id]["link"], lp_bugs[id]["status"]) + add_comments(bug_id, -1, lp_bugs[id]["messages"]) def get_lp_bugs(): """Get a list of bugs from Launchpad""" + package = lp_get_package(LP_SOURCE_NAME) + open_bugs = lp_package_get_bugs(package, LP_OPEN_STATUS_LIST, True) + closed_bugs = lp_package_get_bugs(package, LP_CLOSED_STATUS_LIST, False) + + return {**open_bugs, **closed_bugs} + + +def get_gh_bugs(): + """Get the list of the LP bug already tracked in GitHub. + + Launchpad bugs tracked on GitHub have a title like + + "LP# " + + this function returns a list of the "LP#<id>" substring for each bug, + open or closed, found on the repository on GitHub. + """ + + output = subprocess.check_output( + ["hub", "issue", "--labels", "Launchpad", "--state", "all", "--format", "%I|%S|%L|%t%n"] + ) + bugs = {} + for line in output.decode().split("\n"): + issue = parse_gh_issue(line) + if issue is not None: + bugs[issue["lpid"]] = issue + return bugs + + +def create_issue(id, title, weblink, status): + """ Create a new Bug using HUB """ + print("creating:", id, title, weblink, status) + return gh_create_issue("LP#{} {}".format(id, title), + "Reported first on Launchpad at {}".format(weblink), + "Launchpad,%s" % status) + + +def update_issue(id, current_labels, status): + """ Update a Bug using HUB """ + print("updating:", id, status) + new_labels = ["Launchpad", status] + current_labels + gh_set_issue_labels(id, ",".join(new_labels)) + + +def close_issue(id, current_labels, status): + """ Close the Bug using HUB and leave a comment """ + print("closing:", id, status) + new_labels = ["Launchpad", status] + current_labels + gh_add_comment(id, "Issue closed on Launchpad with status: {}".format(status)) + gh_close_issue(id, ",".join(new_labels)) + + +def add_comments(issue_id, last_comment_id, comments): + for id in comments: + if id > last_comment_id: + print("adding comment:", issue_id, id) + gh_add_comment(issue_id, format_lp_comment(comments[id])) + + +def quote_str(string): + content = [] + for line in string.split("\n"): + content.append("> {}".format(line)) + return "\n".join(content) + + +def format_lp_comment(message): + output = "[LP#{}]({}): *{} ({}) wrote on {}:*\n\n{}".format(message["id"], + message["link"], + message["author"]["display_name"], + message["author"]["name"], + message["date"], + quote_str(message["content"])) + if len(message["attachments"]) > 0: + output += "\n\nAttachments:" + for attachment in message["attachments"]: + output += "\n- [{}]({})".format(attachment["title"], + attachment["link"]) + return output + + +def parse_gh_issue(issue): + if "LP#" in issue: + id, status, labels, lp = issue.strip().split("|", 3) + labels = labels.split(", ") + lpid, title = lp.split(" ", 1) + lpid = lpid[3:] + return {"id": id, "lpid": lpid, "status": status, "title": title, "labels": labels} + return None + + +def parse_gh_labels(labels): + result = { + "status": "Unknown", + "labels": [] + } + for label in labels: + if label == "Launchpad": + continue + elif label in LP_OPEN_STATUS_LIST + LP_CLOSED_STATUS_LIST: + result["status"] = label + else: + result["labels"].append(label) + return result + + +def get_gh_last_lp_comment(issue_id): + comments = gh_list_comments(issue_id) + last_comment_id = -1 + for comment in comments: + if comment["body"][0:4] == "[LP#": + comment_id = comment["body"].split("]")[0] + comment_id = comment_id[4:] + comment_id = int(comment_id) + if comment_id > last_comment_id: + last_comment_id = comment_id + return last_comment_id + + +# Launchpad API +def lp_get_package(source_name): lp = Launchpad.login_anonymously( "%s LP bug checker" % LP_SOURCE_NAME, "production", CACHEDIR, version="devel" ) @@ -50,82 +192,120 @@ def get_lp_bugs(): ubuntu = lp.distributions["ubuntu"] archive = ubuntu.main_archive - packages = archive.getPublishedSources(source_name=LP_SOURCE_NAME) + packages = archive.getPublishedSources(source_name=source_name) package = ubuntu.getSourcePackage(name=packages[0].source_package_name) - bug_tasks = package.searchTasks(status=["New", "Opinion", - "Invalid", "Won't Fix", - "Expired", "Confirmed", - "Triaged", "In Progress", - "Fix Committed", "Fix Released", - "Incomplete"]) + return package + + +def lp_package_get_bugs(package, status_list, get_messages = False): + """Get a list of bugs from Launchpad""" + + bug_tasks = package.searchTasks(status=status_list) bugs = {} for task in bug_tasks: + bug = lp_task_get_bug(task, get_messages) + if bug is not None: + bugs[bug["id"]] = bug + + return bugs + + +def lp_task_get_bug(task, get_messages = False): + try: id = str(task.bug.id) - title = task.title.split(": ")[1] + title = task.title.split(": ", 1)[1] status = task.status - closed = status in ["Invalid", "Won't Fix", "Expired", "Fix Released"] + closed = status in LP_CLOSED_STATUS_LIST link = "https://bugs.launchpad.net/ubuntu/+source/{}/+bug/{}".format(LP_SOURCE_URL_NAME, id) - bugs[id] = {"title": title, "link": link, "status": status, "closed": closed} + if get_messages: + messages = lp_bug_get_messages(task.bug) + else: + messages = {} + return {"id": id, "title": title, "link": link, "status": status, "closed": closed, "messages": messages} + except: + return None - return bugs +def lp_bug_get_messages(bug): + messages = {} + for message in bug.messages: + message_id = lp_message_get_id(message) + messages[message_id] = { + "id": str(message_id), + "link": message.web_link, + "content": message.content, + "date": lp_message_get_date_time(message), + "author": lp_message_get_author(message), + "attachments": lp_message_get_attachments(message) + } + return messages -def get_gh_bugs(): - """Get the list of the LP bug already tracked in GitHub. - Launchpad bugs tracked on GitHub have a title like +def lp_message_get_author(message): + return { + "name": message.owner.name, + "display_name": message.owner.display_name, + } - "LP#<id> <title>" - this function returns a list of the "LP#<id>" substring for each bug, - open or closed, found on the repository on GitHub. - """ +def lp_message_get_id(message): + return int(message.web_link.split("/")[-1]) - output = subprocess.check_output( - ["hub", "issue", "--labels", "Launchpad", "--state", "all", "--format", "%I %S %t%n"] - ) - bugs = {} - for line in output.decode().split("\n"): - if "LP#" in line: - id, status, lpid, title = line.strip().split(" ", 3) - lpid = lpid[3:] - bugs[lpid] = {"id": id, "status": status, "title": title} - return bugs +def lp_message_get_date_time(message): + dt = message.date_created + dt = dt.isoformat().split(".")[0] + dt = dt.split("T")[0] + return dt -def create_issue(id, title, weblink): - """ Create a new Bug using HUB """ - print("creating:", id, title, weblink) - subprocess.run( + +def lp_message_get_attachments(message): + attachments = [] + for attach in message.bug_attachments: + attachments.append({ + "link": attach.data_link, + "title": attach.title + }) + return attachments + + +# GitHub API +def gh_create_issue(summary, description, labels): + url = subprocess.check_output( [ "hub", "issue", "create", "--message", - "LP#{} {}".format(id, title), + summary, "--message", - "Reported first on Launchpad at {}".format(weblink), + description, "-l", - "Launchpad", + labels ] ) + url = url.decode("utf-8") + url = url.strip() + id = url.split("/")[-1] + return id -def close_issue(id, status): - """ Close the Bug using HUB and leave a comment """ - print("closing:", id, status) +def gh_set_issue_labels(id, labels): subprocess.run( [ "hub", - "api", - "repos/{}/{}/issues/{}/comments".format(GH_OWNER, GH_REPO, id), - "--field", - "body=Issue closed on Launchpad with status: {}".format(status) + "issue", + "update", + id, + "-l", + labels, ] ) + +def gh_close_issue(id, labels): subprocess.run( [ "hub", @@ -133,9 +313,34 @@ def close_issue(id, status): "update", id, "--state", - "closed" + "closed", + "-l", + labels, + ] + ) + + +def gh_add_comment(issue_id, comment): + subprocess.run( + [ + "hub", + "api", + "repos/{}/{}/issues/{}/comments".format(GH_OWNER, GH_REPO, issue_id), + "--field", + "body={}".format(comment) + ] + ) + + +def gh_list_comments(issue_id): + output = subprocess.check_output( + [ + "hub", + "api", + "repos/{}/{}/issues/{}/comments".format(GH_OWNER, GH_REPO, issue_id) ] ) + return json.loads(output) if __name__ == "__main__":