Skip to content

Commit

Permalink
Enable private project configuration; 7
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchane committed Oct 26, 2023
1 parent 51d7b84 commit 4da12a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
9 changes: 5 additions & 4 deletions src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl ReferenceSignatures {
config: &tracker::Config,
) -> Result<Self> {
let mut signatures: HashMap<Arc<TicketQuery>, Vec<String>> = HashMap::new();
Self::store(&mut signatures, ref_bugs, &config.bugzilla)?;
Self::store(&mut signatures, ref_issues, &config.jira)?;
Self::store(&mut signatures, ref_bugs, &config.bugzilla, &config)?;
Self::store(&mut signatures, ref_issues, &config.jira, &config)?;

// For each ticket, sort its references alphabetically.
// Otherwise, the order changes based on the response from the ticket tracker,
Expand All @@ -76,10 +76,11 @@ impl ReferenceSignatures {
fn store<T: IntoAbstract>(
signatures: &mut HashMap<Arc<TicketQuery>, Vec<String>>,
ref_issues: Vec<(Arc<TicketQuery>, T)>,
config: &impl tracker::FieldsConfig,
fields: &impl tracker::FieldsConfig,
config: &tracker::Config,
) -> Result<()> {
for (query, issue) in ref_issues {
let ticket = issue.into_abstract(None, config)?;
let ticket = issue.into_abstract(None, fields, config)?;
signatures
.entry(query)
.and_modify(|e| e.push(ticket.signature()))
Expand Down
40 changes: 23 additions & 17 deletions src/ticket_abstraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ pub trait IntoAbstract {
self,
references: Option<Vec<String>>,
config: &impl tracker::FieldsConfig,
config: &tracker::Config,
) -> Result<AbstractTicket>;
}

impl IntoAbstract for Bug {
fn into_abstract(
self,
references: Option<Vec<String>>,
config: &impl tracker::FieldsConfig,
fields: &impl tracker::FieldsConfig,
_config: &tracker::Config,
) -> Result<AbstractTicket> {
let ticket = AbstractTicket {
id: Rc::new(TicketId {
Expand All @@ -133,13 +135,13 @@ impl IntoAbstract for Bug {
}),
// TODO: Find out how to get the bug description from comment#0 with Bugzilla
description: None,
doc_type: self.doc_type(config)?,
doc_text: self.doc_text(config)?,
target_releases: self.target_releases(config),
subsystems: self.subsystems(config).map_err(|e| e.to_string()),
doc_text_status: self.doc_text_status(config)?,
docs_contact: self.docs_contact(config),
url: self.url(config),
doc_type: self.doc_type(fields)?,
doc_text: self.doc_text(fields)?,
target_releases: self.target_releases(fields),
subsystems: self.subsystems(fields).map_err(|e| e.to_string()),
doc_text_status: self.doc_text_status(fields)?,
docs_contact: self.docs_contact(fields),
url: self.url(fields),
summary: self.summary,
status: self.status,
resolution: Some(self.resolution),
Expand Down Expand Up @@ -172,17 +174,18 @@ impl IntoAbstract for Issue {
fn into_abstract(
self,
references: Option<Vec<String>>,
config: &impl tracker::FieldsConfig,
fields: &impl tracker::FieldsConfig,
config: &tracker::Config,
) -> Result<AbstractTicket> {
let ticket = AbstractTicket {
doc_type: self.doc_type(config)?,
doc_text: self.doc_text(config)?,
doc_type: self.doc_type(fields)?,
doc_text: self.doc_text(fields)?,
// The target release is non-essential. Discard the error and store as Option.
target_releases: self.target_releases(config),
doc_text_status: self.doc_text_status(config)?,
docs_contact: self.docs_contact(config),
subsystems: self.subsystems(config).map_err(|e| e.to_string()),
url: self.url(config),
target_releases: self.target_releases(fields),
doc_text_status: self.doc_text_status(fields)?,
docs_contact: self.docs_contact(fields),
subsystems: self.subsystems(fields).map_err(|e| e.to_string()),
url: self.url(fields),
// The ID in particular is wrapped in Rc because it's involved in various filters
// and comparisons where ownership is complicated.
id: Rc::new(TicketId {
Expand All @@ -201,6 +204,7 @@ impl IntoAbstract for Issue {
// Issues might not be assigned to anyone.
assignee: self.fields.assignee.map(|a| a.name),
components: self.fields.components.into_iter().map(|c| c.name).collect(),
// The project name isn't exactly the product name, but it's the closest equivalent at hand.
product: self.fields.project.name,
labels: Some(self.fields.labels),
// Jira does not support flags
Expand All @@ -210,7 +214,9 @@ impl IntoAbstract for Issue {
// If there are no s`fields.security` settings, the ticket is public. If there are some, it's private.
// However, the project as a whole can be public or private, which affects the ticket visibility.
// All projects are considered public unless you configure them in `JiraInstance::private_projects`.
public: self.fields.security.is_none(),
public: {
self.fields.security.is_none() && !config.jira.private_projects.contains(&self.fields.project.key)
},
references,
};

Expand Down
7 changes: 5 additions & 2 deletions src/tracker_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ pub async fn unsorted_tickets(
annotated_tickets.append(&mut into_annotated_tickets(
plain_bugs,
&trackers.bugzilla,
&trackers,
&ref_signatures,
)?);
annotated_tickets.append(&mut into_annotated_tickets(
plain_issues,
&trackers.jira,
&trackers,
&ref_signatures,
)?);

Expand All @@ -161,15 +163,16 @@ pub async fn unsorted_tickets(
/// Convert bugs and issues into abstract tickets.
fn into_annotated_tickets(
issues: Vec<(Arc<TicketQuery>, impl IntoAbstract)>,
config: &impl tracker::FieldsConfig,
fields: &impl tracker::FieldsConfig,
config: &tracker::Config,
ref_signatures: &ReferenceSignatures,
) -> Result<Vec<AnnotatedTicket>> {
// Using an imperative style so that each `into_abstract` call can return an error.
let mut results = Vec::new();

for (query, issue) in issues {
let attached_references = ref_signatures.reattach_to(&query);
let ticket = issue.into_abstract(Some(attached_references), config)?;
let ticket = issue.into_abstract(Some(attached_references), fields, config)?;
let annotated = AnnotatedTicket { ticket, query };
results.push(annotated);
}
Expand Down

0 comments on commit 4da12a0

Please sign in to comment.