Skip to content

Commit 740344d

Browse files
committed
import octo state enums for clarity
1 parent bebbb17 commit 740344d

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

src/concourse.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ use serde::{Deserialize, Serialize};
55

66
use concourse_resource::IntoMetadataKV;
77
use octocrab;
8+
use octocrab::models::IssueState;
89

910
// standard concourse structs
1011
// check input and (vec seralized to list) output, out output
1112
#[derive(Eq, PartialEq, Serialize, Deserialize, Debug)]
1213
pub(super) struct Version {
13-
state: octocrab::models::IssueState,
14+
state: IssueState,
1415
}
1516

1617
impl Version {
1718
/// Constructor
1819
/// ```
19-
/// let version = Version::new(octocrab::models::IssueState::Closed);
20+
/// let version = Version::new(IssueState::Closed);
2021
/// ```
21-
pub(super) fn new(state: octocrab::models::IssueState) -> Self {
22+
pub(super) fn new(state: IssueState) -> Self {
2223
Version { state }
2324
}
2425
}
@@ -40,7 +41,7 @@ pub(super) struct Source {
4041
// for skipping check during e.g. put+create
4142
skip_check: Option<bool>,
4243
// trigger on issue state open or closed
43-
trigger: Option<octocrab::models::IssueState>,
44+
trigger: Option<IssueState>,
4445
}
4546

4647
impl Source {
@@ -78,10 +79,8 @@ impl Source {
7879
self.skip_check.unwrap_or(false)
7980
}
8081
// return unwrapped value with default closed for ease of use
81-
pub(super) fn trigger(&self) -> octocrab::models::IssueState {
82-
self.trigger
83-
.clone()
84-
.unwrap_or(octocrab::models::IssueState::Closed)
82+
pub(super) fn trigger(&self) -> IssueState {
83+
self.trigger.clone().unwrap_or(IssueState::Closed)
8584
}
8685
}
8786

@@ -126,7 +125,7 @@ pub(super) struct OutMetadata {
126125
number: u64,
127126
url: String,
128127
title: String,
129-
state: octocrab::models::IssueState,
128+
state: IssueState,
130129
#[serde(skip_serializing_if = "Vec::is_empty")]
131130
labels: Vec<octocrab::models::Label>,
132131
#[serde(skip_serializing_if = "Vec::is_empty")]
@@ -144,7 +143,7 @@ impl OutMetadata {
144143
/// 5,
145144
/// String::from("http://does.not.exist"),
146145
/// String::from("some issue"),
147-
/// octocrab::models::IssueState::Open,
146+
/// IssueState::Open,
148147
/// vec![],
149148
/// vec![],
150149
/// None,
@@ -157,7 +156,7 @@ impl OutMetadata {
157156
number: u64,
158157
url: impl Into<String>,
159158
title: String,
160-
state: octocrab::models::IssueState,
159+
state: IssueState,
161160
labels: Vec<octocrab::models::Label>,
162161
assignees: Vec<octocrab::models::Author>,
163162
milestone: Option<octocrab::models::Milestone>,

src/github_issue.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use log;
55

66
use octocrab;
7+
use octocrab::models::IssueState;
8+
use octocrab::params::State;
79

810
// allowed operations for github issue interactions
911
#[non_exhaustive]
@@ -28,27 +30,27 @@ impl From<Action> for String {
2830
}
2931
}
3032

31-
// convert string to IssueState or params::State without trait implementations because not allowed (no impl Into<octocrab::models::IssueState> for &str)
32-
fn str_to_issue_state(param: &str) -> Result<octocrab::models::IssueState, &str> {
33+
// convert string to IssueState or params::State without trait implementations because not allowed (no impl Into<IssueState> for &str)
34+
fn str_to_issue_state(param: &str) -> Result<IssueState, &str> {
3335
match param {
34-
"open" => Ok(octocrab::models::IssueState::Open),
35-
"closed" => Ok(octocrab::models::IssueState::Closed),
36+
"open" => Ok(IssueState::Open),
37+
"closed" => Ok(IssueState::Closed),
3638
"all" => {
3739
log::warn!(
3840
"all was specified for issue state, and this can only be utilized with issue filtering, and not updating"
3941
);
4042
log::warn!("the issue state will be reset to 'open'");
41-
Ok(octocrab::models::IssueState::Open)
43+
Ok(IssueState::Open)
4244
}
4345
&_ => Err("the issue state must be either open or closed"),
4446
}
4547
}
4648

47-
fn str_to_params_state(param: &str) -> Result<octocrab::params::State, &str> {
49+
fn str_to_params_state(param: &str) -> Result<State, &str> {
4850
match param {
49-
"open" => Ok(octocrab::params::State::Open),
50-
"closed" => Ok(octocrab::params::State::Closed),
51-
"all" => Ok(octocrab::params::State::All),
51+
"open" => Ok(State::Open),
52+
"closed" => Ok(State::Closed),
53+
"all" => Ok(State::All),
5254
&_ => Err("the issue state must be either open, closed, or all"),
5355
}
5456
}
@@ -68,7 +70,7 @@ pub(super) struct Issue<'issue> {
6870
assignees: Option<Vec<String>>,
6971
// read and update
7072
number: Option<u64>,
71-
// update octocrab::models::IssueState and list octocrab::params::State
73+
// update IssueState and list State
7274
state: Option<&'issue str>,
7375
// create, list, and update
7476
milestone: Option<u64>,

src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use env_logger;
22
use log;
33

44
use concourse_resource::*;
5-
use octocrab;
5+
use octocrab::models::IssueState;
66

77
mod concourse;
88
mod github_issue;
@@ -37,8 +37,8 @@ impl concourse_resource::Resource for GithubIssue {
3737
"the check step will be skipped because 'skip_check' was set to true in source"
3838
);
3939
return vec![
40-
concourse::Version::new(octocrab::models::IssueState::Open),
41-
concourse::Version::new(octocrab::models::IssueState::Closed),
40+
concourse::Version::new(IssueState::Open),
41+
concourse::Version::new(IssueState::Closed),
4242
];
4343
}
4444

@@ -76,11 +76,11 @@ impl concourse_resource::Resource for GithubIssue {
7676
// return two sized version vector if issue state matches trigger, and one sized if otherwise
7777
if issue.state == source.trigger() {
7878
vec![
79-
concourse::Version::new(octocrab::models::IssueState::Open),
80-
concourse::Version::new(octocrab::models::IssueState::Closed),
79+
concourse::Version::new(IssueState::Open),
80+
concourse::Version::new(IssueState::Closed),
8181
]
8282
} else {
83-
vec![concourse::Version::new(octocrab::models::IssueState::Open)]
83+
vec![concourse::Version::new(IssueState::Open)]
8484
}
8585
}
8686

@@ -105,7 +105,7 @@ impl concourse_resource::Resource for GithubIssue {
105105
"there is no actual functionality for the in step, and the version and metadata are dummied"
106106
);
107107
Ok(concourse_resource::InOutput {
108-
version: concourse::Version::new(octocrab::models::IssueState::Open),
108+
version: concourse::Version::new(IssueState::Open),
109109
metadata: None,
110110
})
111111
}
@@ -177,7 +177,7 @@ impl concourse_resource::Resource for GithubIssue {
177177

178178
// return out step output
179179
concourse_resource::OutOutput {
180-
version: concourse::Version::new(octocrab::models::IssueState::Open),
180+
version: concourse::Version::new(IssueState::Open),
181181
metadata: Some(concourse::OutMetadata::new(
182182
issue.number,
183183
issue.url,

0 commit comments

Comments
 (0)