• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

UiPath / uipathcli / 13765865558

10 Mar 2025 01:27PM UTC coverage: 90.218% (+0.1%) from 90.121%
13765865558

push

github

thschmitt
Add network package with common http client

Moved common code for handling HTTP requests in a new shared
network package to avoid duplication and ensure that each plugin
handles network requests the same way.

The common HTTP client code takes care of a couple of cross-cutting
concerns needed by all plugins and the main HTTP executor:

- Logs request and response when debug flag is set. Added a new
  resettableReader which preserves the request and response bodies while
  they are being read and forwards them to the debug logger.

- Added retries for all HTTP requests. This also leverages the
  resettableReader to ensure the request body can be replayed.

- The `CommandBuilder` generates now an operation id which is set on every
  request the uipathcli performs. The same operation id is kept for the
  duration of the whole command execution which makes it easier to
  correlate multiple requests performed by a single command.

- The `HttpClient` also sets transport-related settings like certificate
  validation and response header timeout.

- Using the built-in context instead of a custom requestError channel.

369 of 384 new or added lines in 22 files covered. (96.09%)

7 existing lines in 4 files now uncovered.

5340 of 5919 relevant lines covered (90.22%)

1.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/utils/visualization/progress_bar.go
1
package visualization
2

3
import (
4
        "fmt"
5
        "math"
6
        "strings"
7
        "unicode/utf8"
8

9
        "github.com/UiPath/uipathcli/log"
10
)
11

12
// The ProgressBar helps rendering a text-based progress indicator on the command-line.
13
// It uses the standard error output interface of the logger for writing progress.
14
type ProgressBar struct {
15
        logger         log.Logger
16
        renderedLength int
17
}
18

19
func (b *ProgressBar) UpdatePercentage(text string, percent float64) {
1✔
20
        b.logger.LogError("\r")
1✔
21
        length := b.renderTick(text, percent)
1✔
22
        left := b.renderedLength - length
1✔
23
        if left > 0 {
1✔
24
                b.logger.LogError(strings.Repeat(" ", left))
×
25
        }
×
26
        b.renderedLength = length
1✔
27
}
28

29
func (b *ProgressBar) UpdateProgress(text string, current int64, total int64, bytesPerSecond int64) {
1✔
30
        b.logger.LogError("\r")
1✔
31
        length := b.renderProgress(text, current, total, bytesPerSecond)
1✔
32
        left := b.renderedLength - length
1✔
33
        if left > 0 {
2✔
34
                b.logger.LogError(strings.Repeat(" ", left))
1✔
35
        }
1✔
36
        b.renderedLength = length
1✔
37
}
38

39
func (b *ProgressBar) Remove() {
1✔
40
        if b.renderedLength > 0 {
2✔
41
                clear := fmt.Sprintf("\r%s\r", strings.Repeat(" ", b.renderedLength))
1✔
42
                b.logger.LogError(clear)
1✔
43
        }
1✔
44
}
45

46
func (b ProgressBar) renderTick(text string, percent float64) int {
1✔
47
        bar := b.createBar(percent)
1✔
48
        output := fmt.Sprintf("%s      |%s|",
1✔
49
                text,
1✔
50
                bar)
1✔
51
        b.logger.LogError(output)
1✔
52
        return utf8.RuneCountInString(output)
1✔
53
}
1✔
54

55
func (b ProgressBar) renderProgress(text string, currentBytes int64, totalBytes int64, bytesPerSecond int64) int {
1✔
56
        percent := math.Min(float64(currentBytes)/float64(totalBytes)*100.0, 100.0)
1✔
57
        bar := b.createBar(percent)
1✔
58
        totalBytesFormatted, unit := b.formatBytes(totalBytes)
1✔
59
        currentBytesFormatted, unit := b.formatBytesInUnit(currentBytes, unit)
1✔
60
        bytesPerSecondFormatted, bytesPerSecondUnit := b.formatBytes(bytesPerSecond)
1✔
61
        output := fmt.Sprintf("%s %3d%% |%s| (%s/%s %s, %s %s/s)",
1✔
62
                text,
1✔
63
                int(percent),
1✔
64
                bar,
1✔
65
                currentBytesFormatted,
1✔
66
                totalBytesFormatted,
1✔
67
                unit,
1✔
68
                bytesPerSecondFormatted,
1✔
69
                bytesPerSecondUnit)
1✔
70
        b.logger.LogError(output)
1✔
71
        return utf8.RuneCountInString(output)
1✔
72
}
1✔
73

74
func (b ProgressBar) createBar(percent float64) string {
1✔
75
        barCount := int(percent / 5.0)
1✔
76
        if barCount > 20 {
1✔
77
                barCount = 20
×
78
        }
×
79
        return strings.Repeat("█", barCount) + strings.Repeat(" ", 20-barCount)
1✔
80
}
81

82
func (b ProgressBar) formatBytes(count int64) (string, string) {
1✔
83
        if count < 1000 {
2✔
84
                return b.formatBytesInUnit(count, "B")
1✔
85
        }
1✔
86
        if count < 1000*1000 {
2✔
87
                return b.formatBytesInUnit(count, "kB")
1✔
88
        }
1✔
89
        if count < 1000*1000*1000 {
2✔
90
                return b.formatBytesInUnit(count, "MB")
1✔
91
        }
1✔
UNCOV
92
        return b.formatBytesInUnit(count, "GB")
×
93
}
94

95
func (b ProgressBar) formatBytesInUnit(count int64, unit string) (string, string) {
1✔
96
        if unit == "B" {
2✔
97
                return fmt.Sprintf("%d", count), unit
1✔
98
        }
1✔
99
        if unit == "kB" {
2✔
100
                return fmt.Sprintf("%0.1f", float64(count)/1_000), unit
1✔
101
        }
1✔
102
        if unit == "MB" {
2✔
103
                return fmt.Sprintf("%0.1f", float64(count)/1_000_000), unit
1✔
104
        }
1✔
UNCOV
105
        return fmt.Sprintf("%0.1f", float64(count)/1_000_000_000), unit
×
106
}
107

108
func NewProgressBar(logger log.Logger) *ProgressBar {
1✔
109
        return &ProgressBar{logger, 0}
1✔
110
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc