Skip to content

Commit dff2c43

Browse files
committed
feat(gh_actions): implement gh_actions segment
1 parent 56741ce commit dff2c43

File tree

9 files changed

+450
-6
lines changed

9 files changed

+450
-6
lines changed

src/command/config/agnoster.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,40 @@ git_user:
182182
decoration: []
183183
content: "  {{.name}} "
184184

185+
gh_actions:
186+
icons:
187+
in_progress: ""
188+
success: ""
189+
failure: ""
190+
cancelled: ""
191+
skipped: ""
192+
in_progress:
193+
style:
194+
foreground: black
195+
background: 226
196+
decoration: []
197+
success:
198+
style:
199+
foreground: white
200+
background: 34
201+
decoration: []
202+
failure:
203+
style:
204+
foreground: white
205+
background: 196
206+
decoration: []
207+
cancelled:
208+
style:
209+
foreground: white
210+
background: 244
211+
decoration: []
212+
skipped:
213+
style:
214+
foreground: white
215+
background: 244
216+
decoration: []
217+
content: " {{.status}} "
218+
185219
gh_pull_request:
186220
icons:
187221
open: ""
@@ -282,6 +316,7 @@ segments:
282316
- path
283317
- git_status
284318
- gh_pull_request
319+
- gh_actions
285320
- glab_merge_request
286321
- git_user
287322
right:

src/config/gh_actions.rs

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
use serde::Deserialize;
2+
3+
use super::style::{Color, NamedColor, Style};
4+
5+
#[derive(Debug, Deserialize)]
6+
pub struct GhActionsConfig {
7+
#[serde(default)]
8+
pub icons: ActionsIcons,
9+
10+
#[serde(default)]
11+
pub in_progress: InProgressConfig,
12+
13+
#[serde(default)]
14+
pub success: SuccessConfig,
15+
16+
#[serde(default)]
17+
pub failure: FailureConfig,
18+
19+
#[serde(default)]
20+
pub cancelled: CancelledConfig,
21+
22+
#[serde(default)]
23+
pub skipped: SkippedConfig,
24+
25+
#[serde(default = "GhActionsConfig::default_content")]
26+
pub content: String,
27+
}
28+
29+
impl GhActionsConfig {
30+
fn default_content() -> String {
31+
" {{.status}} ".to_string()
32+
}
33+
}
34+
35+
impl Default for GhActionsConfig {
36+
fn default() -> Self {
37+
Self {
38+
icons: Default::default(),
39+
in_progress: Default::default(),
40+
success: Default::default(),
41+
failure: Default::default(),
42+
cancelled: Default::default(),
43+
skipped: Default::default(),
44+
content: Self::default_content(),
45+
}
46+
}
47+
}
48+
49+
#[derive(Debug, Deserialize)]
50+
pub struct ActionsIcons {
51+
#[serde(default = "ActionsIcons::default_in_progress")]
52+
pub in_progress: String,
53+
54+
#[serde(default = "ActionsIcons::default_success")]
55+
pub success: String,
56+
57+
#[serde(default = "ActionsIcons::default_failure")]
58+
pub failure: String,
59+
60+
#[serde(default = "ActionsIcons::default_cancelled")]
61+
pub cancelled: String,
62+
63+
#[serde(default = "ActionsIcons::default_skipped")]
64+
pub skipped: String,
65+
}
66+
67+
impl ActionsIcons {
68+
fn default_in_progress() -> String {
69+
"".to_string()
70+
}
71+
72+
fn default_success() -> String {
73+
"".to_string()
74+
}
75+
76+
fn default_failure() -> String {
77+
"".to_string()
78+
}
79+
80+
fn default_cancelled() -> String {
81+
"".to_string()
82+
}
83+
84+
fn default_skipped() -> String {
85+
"".to_string()
86+
}
87+
}
88+
89+
impl Default for ActionsIcons {
90+
fn default() -> Self {
91+
Self {
92+
in_progress: Self::default_in_progress(),
93+
success: Self::default_success(),
94+
failure: Self::default_failure(),
95+
cancelled: Self::default_cancelled(),
96+
skipped: Self::default_skipped(),
97+
}
98+
}
99+
}
100+
101+
#[derive(Debug, Deserialize)]
102+
pub struct InProgressConfig {
103+
#[serde(default = "InProgressConfig::default_style")]
104+
pub style: Style,
105+
}
106+
107+
impl InProgressConfig {
108+
fn default_style() -> Style {
109+
Style {
110+
foreground: Color::Named(NamedColor::Black),
111+
background: Color::Fixed(226),
112+
decoration: vec![],
113+
}
114+
}
115+
}
116+
117+
impl Default for InProgressConfig {
118+
fn default() -> Self {
119+
Self {
120+
style: Self::default_style(),
121+
}
122+
}
123+
}
124+
125+
#[derive(Debug, Deserialize)]
126+
pub struct SuccessConfig {
127+
#[serde(default = "SuccessConfig::default_style")]
128+
pub style: Style,
129+
}
130+
131+
impl SuccessConfig {
132+
fn default_style() -> Style {
133+
Style {
134+
foreground: Color::Named(NamedColor::White),
135+
background: Color::Fixed(34),
136+
decoration: vec![],
137+
}
138+
}
139+
}
140+
141+
impl Default for SuccessConfig {
142+
fn default() -> Self {
143+
Self {
144+
style: Self::default_style(),
145+
}
146+
}
147+
}
148+
149+
#[derive(Debug, Deserialize)]
150+
pub struct FailureConfig {
151+
#[serde(default = "FailureConfig::default_style")]
152+
pub style: Style,
153+
}
154+
155+
impl FailureConfig {
156+
fn default_style() -> Style {
157+
Style {
158+
foreground: Color::Named(NamedColor::White),
159+
background: Color::Fixed(196),
160+
decoration: vec![],
161+
}
162+
}
163+
}
164+
165+
impl Default for FailureConfig {
166+
fn default() -> Self {
167+
Self {
168+
style: Self::default_style(),
169+
}
170+
}
171+
}
172+
173+
#[derive(Debug, Deserialize)]
174+
pub struct CancelledConfig {
175+
#[serde(default = "CancelledConfig::default_style")]
176+
pub style: Style,
177+
}
178+
179+
impl CancelledConfig {
180+
fn default_style() -> Style {
181+
Style {
182+
foreground: Color::Named(NamedColor::White),
183+
background: Color::Fixed(244),
184+
decoration: vec![],
185+
}
186+
}
187+
}
188+
189+
impl Default for CancelledConfig {
190+
fn default() -> Self {
191+
Self {
192+
style: Self::default_style(),
193+
}
194+
}
195+
}
196+
197+
#[derive(Debug, Deserialize)]
198+
pub struct SkippedConfig {
199+
#[serde(default = "SkippedConfig::default_style")]
200+
pub style: Style,
201+
}
202+
203+
impl SkippedConfig {
204+
fn default_style() -> Style {
205+
Style {
206+
foreground: Color::Named(NamedColor::White),
207+
background: Color::Fixed(244),
208+
decoration: vec![],
209+
}
210+
}
211+
}
212+
213+
impl Default for SkippedConfig {
214+
fn default() -> Self {
215+
Self {
216+
style: Self::default_style(),
217+
}
218+
}
219+
}

src/config/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod direnv;
22
pub mod duration;
3+
pub mod gh_actions;
34
pub mod gh_pull_request;
45
pub mod git_status;
56
pub mod git_user;
@@ -11,6 +12,8 @@ pub mod style;
1112
pub mod time;
1213
pub mod user;
1314

15+
use crate::config::gh_actions::GhActionsConfig;
16+
1417
use self::{
1518
duration::DurationConfig, gh_pull_request::GhPullRequestConfig, git_status::GitStatusConfig,
1619
git_user::GitUserConfig, glab_merge_request::GlabMergeRequestConfig, os::OsConfig,
@@ -53,6 +56,9 @@ pub struct Config {
5356
#[serde(default)]
5457
pub git_user: GitUserConfig,
5558

59+
#[serde(default)]
60+
pub gh_actions: GhActionsConfig,
61+
5662
#[serde(default)]
5763
pub gh_pull_request: GhPullRequestConfig,
5864

@@ -149,6 +155,7 @@ impl Default for Config {
149155
time: Default::default(),
150156
git_status: Default::default(),
151157
git_user: Default::default(),
158+
gh_actions: Default::default(),
152159
gh_pull_request: Default::default(),
153160
glab_merge_request: Default::default(),
154161
direnv: Default::default(),
@@ -223,6 +230,7 @@ pub enum SegmentKind {
223230
GitStatus,
224231
GitUser,
225232
GhPullRequest,
233+
GhActions,
226234
GlabMergeRequest,
227235
Direnv,
228236
}

0 commit comments

Comments
 (0)