Esempio n. 1
0
    def print_formatted_list(self) -> None:
        """
        Print the list of pipelines to terminal formatted as a table
        """
        table = Table()

        # Compute args that are sent to GitLab
        args: Dict[str, str] = {}
        if self.status is not None:
            # Only yield pipelines that have the specific status
            # If empty all pipelines will be returned by GitLab
            args["status"] = str(self.status)

        if self.ref is not None:
            # Only yield pipeline that match a given reference
            args["ref"] = self.ref

        # Build the printable table
        pipelines: List[ProjectPipeline] = self._remote_project.pipelines.list(
            **args)
        for pipeline in pipelines:
            row: List[str] = [
                TextFormatting.BOLD + "#" + str(pipeline.id) +
                TextFormatting.END,
                pipeline.ref,
                Utils.pretty_date(pipeline.created_at),
                PipelineStatus.format(pipeline.status),
            ]
            table.add_row(row)

        table.print()
Esempio n. 2
0
    def test_timezone_awareness_of_pretty_date(self) -> None:
        ref_date = datetime(2020, 1, 1, tzinfo=timezone.utc)
        fmt = "%Y-%m-%dT%H:%M:%S.%fZ"

        iso_date_1 = ref_date + timedelta(seconds=9)
        self.assertEqual(
            Utils.pretty_date(
                ref_date.replace(tzinfo=None).strftime(fmt), iso_date_1),
            "just now")
Esempio n. 3
0
    def test_pretty_date(self) -> None:
        ref_date = datetime(2020, 1, 1)
        fmt = "%Y-%m-%dT%H:%M:%S.%fZ"

        iso_date_1 = ref_date + timedelta(seconds=9)
        self.assertEqual(Utils.pretty_date(ref_date.strftime(fmt), iso_date_1),
                         "just now")

        iso_date_1 = ref_date + timedelta(seconds=59)
        self.assertEqual(Utils.pretty_date(ref_date.strftime(fmt), iso_date_1),
                         "59 seconds ago")

        iso_date_1 = ref_date + timedelta(seconds=5 * 60)
        self.assertEqual(Utils.pretty_date(ref_date.strftime(fmt), iso_date_1),
                         "5 minutes ago")

        iso_date_1 = ref_date + timedelta(seconds=60 * 60)
        self.assertEqual(Utils.pretty_date(ref_date.strftime(fmt), iso_date_1),
                         "an hour ago")

        iso_date_1 = ref_date + timedelta(seconds=24 * 60 * 60)
        self.assertEqual(Utils.pretty_date(ref_date.strftime(fmt), iso_date_1),
                         "Yesterday")

        iso_date_1 = ref_date + timedelta(seconds=14 * 24 * 60 * 60)
        self.assertEqual(Utils.pretty_date(ref_date.strftime(fmt), iso_date_1),
                         "2 weeks ago")