Skip to content

Commit

Permalink
continue list operation implement and milestone in source
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Jul 28, 2023
1 parent 529b178 commit 15c4e01
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ A [concourse-ci](https://concourse-ci.org) resource for interacting with [Github

- `number`: _optional_ The issue number to read during the `check` step for triggering Concourse pipelines based on the issue state. If this is omitted then the `check` step is skipped.

- `milestone`: _optional_ The milestone number to associate with the issue during creation. This is within `source` and not `params` because it may also be used with `check` in the future.

### `version`: designates the Github issue state

**parameters**
Expand Down
9 changes: 8 additions & 1 deletion src/concourse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Version {
}
}

// check and out input TODO update for new members associated with list, and then update doc
// check and out input
#[derive(Eq, PartialEq, Deserialize, Debug)]
pub(crate) struct Source {
// client and issues
Expand All @@ -35,6 +35,8 @@ pub(crate) struct Source {
repo: String,
// read and update
number: Option<u64>,
// create, list, and update
milestone: Option<u64>,
}

impl Source {
Expand All @@ -51,6 +53,9 @@ impl Source {
pub(crate) fn number(&self) -> Option<u64> {
return self.number;
}
pub(crate) fn milestone(&self) -> Option<u64> {
return self.milestone;
}
}

// out input
Expand Down Expand Up @@ -144,6 +149,7 @@ mod tests {
owner: String::from("myorg"),
repo: String::from("myrepo"),
number: None,
milestone: None
}
.owner,
String::from("myorg"),
Expand All @@ -167,6 +173,7 @@ mod tests {
owner: String::from("mitodl"),
repo: String::from("ol-infrastructure"),
number: Some(1),
milestone: None,
},
"source did not contain the expected member values",
)
Expand Down
24 changes: 16 additions & 8 deletions src/github_issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ impl Issue {
// title specified
Some(title) => {
// build the issue
let mut issue = issues.create(title);
// createissuebuilder milestone type is impl Into<Option<u64>> so we can build it immediately
let mut issue = issues.create(title).milestone(self.milestone);
// ... with optional parameters
if self.body.is_some() {
issue = issue.body(self.body.as_ref().unwrap());
Expand Down Expand Up @@ -194,25 +195,29 @@ impl Issue {
}

// list github issues according to configuration
/*async fn list<'octo>(
// https://docs.rs/octocrab/latest/octocrab/issues/struct.ListIssuesBuilder.html
async fn list<'octo>(
&self,
issues: octocrab::issues::IssueHandler<'octo>,
) -> Result<octocrab::Page<octocrab::models::issues::Issue>, &str> {
// build the issue pages
let mut issue_pages = issues.list();
// ... with optional parameters
if self.state.is_some() {
// TODO need issuestate to paramsstate converter
/*if self.state.is_some() {
issue_pages = issue_pages.state(self.state.clone().unwrap());
}
}*/
if self.milestone.is_some() {
issue_pages = issue_pages.milestone(self.milestone.unwrap());
}
if self.assignees.is_some() {
issue_pages = issue_pages.assignee(self.assignees.unwrap())
/*if self.assignees.is_some() {
// assign value of first assignee by unwrapping option, cloning vector to avoid self vector destruction, accessing first item, unwrapping first item, and then referencing for conversion for octocrab trait bound (hooray rust!)
let assignee = &self.assignees.unwrap().clone().into_iter().next().unwrap();
issue_pages = issue_pages.assignee(assignee);
}
// TODO use current user? if self.creator.is_some() {}
// TODO requires converting Option<Vec<String>> to &'d impl AsRef<[String]> + ?Sized which is horrendous
/*if self.labels.is_some() {
if self.labels.is_some() {
let labels = self.labels.clone().unwrap();
issue_pages = issue_pages.labels(&labels[..]);
}*/
Expand All @@ -229,7 +234,7 @@ impl Issue {
return Err("unknown issues");
}
}
}*/
}

// update a github issue according to configuration
async fn update<'octo>(
Expand All @@ -252,6 +257,9 @@ impl Issue {
if self.state.is_some() {
issue = issue.state(self.state.clone().unwrap());
}
if self.milestone.is_some() {
issue = issue.milestone(self.milestone.unwrap());
}
// TODO requires converting Option<Vec<String>> to &'e impl AsRef<[String]> + ?Sized which is horrendous
/*if self.labels.is_some() {
let labels = self.labels.clone().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl concourse_resource::Resource for GithubIssue {
params.assignees(),
None,
None,
None,
source.milestone(),
);
// ...and create the octocrab github issue
let issue = match gh_issue.main(github_issue::Action::Create).await {
Expand Down

0 comments on commit 15c4e01

Please sign in to comment.