async fn send_internal(msg: Message, chan: String, owners: &Owners) -> Result<()> {
    let hook_url: &str = &env_hook_url()?;
    let hook_user: String = env_username();
    let md = &msg.metadata;

    let slack = Slack::new(hook_url)?;

    let mut p = PayloadBuilder::new()
        .channel(chan)
        .icon_emoji(":shipcat:")
        .username(hook_user);

    debug!("Got slack notify {:?}", msg);
    // NB: cannot use .link_names due to https://api.slack.com/changelog/2017-09-the-one-about-usernames
    // NB: cannot use .parse(Parse::Full) as this breaks the other links
    // Thus we have to use full slack names, and construct SlackLink objs manually

    // All text is in either one or two attachments to make output as clean as possible

    // First attachment is main text + main link + CCs
    // Fallbacktext is in constructor here (shown in OSD notifies)
    let mut a = AttachmentBuilder::new(msg.text.clone()); // fallback
    if let Some(c) = msg.color {
        a = a.color(c)
    }
    // All text constructed for first attachment goes in this vec:
    let mut texts = vec![Text(msg.text.into())];

    let mut codeattach = None;
    if let Some(diff) = msg.code {
        // does the diff contain versions?
        let is_version_only = if let Some((v1, v2)) = diff::infer_version_change(&diff) {
            let lnk = create_github_compare_url(&md, (&v1, &v2));
            texts.push(lnk);
            diff::is_version_only(&diff, (&v1, &v2))
        } else {
            false
        };
        // is diff otherwise meaningful?
        if !is_version_only {
            codeattach = Some(
                AttachmentBuilder::new(diff.clone())
                    .color("#439FE0")
                    .text(vec![Text(diff.into())].as_slice())
                    .build()?,
            )
        }
    } else if let Some(v) = msg.version {
        texts.push(infer_metadata_single_link(md, v));
    }

    // Automatic CI originator link
    texts.push(infer_ci_links());

    // Auto cc users
    if let NotificationMode::NotifyMaintainers = msg.mode {
        if !md.contacts.is_empty() || !md.maintainers.is_empty() {
            texts.push(Text("<- ".to_string().into()));
        }
        // maintainer strings via people in teams.yml
        if !md.maintainers.is_empty() {
            texts.extend(maintainers_to_text_content(&md.maintainers, &owners.people))
        }
        // legacy contacts:
        if !md.contacts.is_empty() {
            texts.extend(contacts_to_text_content(&md.contacts));
        }
    }

    // Pass the texts array to slack_hook
    a = a.text(texts.as_slice());
    let mut ax = vec![a.build()?];

    // Second attachment: optional code (blue)
    if let Some(diffattach) = codeattach {
        ax.push(diffattach);
        // Pass attachment vector
    }
    p = p.attachments(ax);

    // Send everything. Phew.
    if msg.mode != NotificationMode::Silent {
        slack.send(&p.build()?).await?;
    }

    Ok(())
}
/// Send a `Message` to a configured slack destination
Send a `Message` to a configured slack destination
Send a ` Message ` to a configured slack destination
async fn send_internal(msg: Message, chan: String, owners: &Owners) -> Result<()> {
    let hook_url: &str = &env_hook_url()?;
    let hook_user: String = env_username();
    let md = &msg.metadata;
    let slack = Slack::new(hook_url)?;
    let mut p = PayloadBuilder::new()
        .channel(chan)
        .icon_emoji(":shipcat:")
        .username(hook_user);
    debug!("Got slack notify {:?}", msg);
    // NB: cannot use .link_names due to https://api.slack.com/changelog/2017-09-the-one-about-usernames
    // NB: cannot use .parse(Parse::Full) as this breaks the other links
    // Thus we have to use full slack names, and construct SlackLink objs manually
    // All text is in either one or two attachments to make output as clean as possible
    // First attachment is main text + main link + CCs
    // Fallbacktext is in constructor here (shown in OSD notifies)
    let mut a = AttachmentBuilder::new(msg.text.clone()); // fallback
    if let Some(c) = msg.color {
        a = a.color(c)
    }
    // All text constructed for first attachment goes in this vec:
    let mut texts = vec![Text(msg.text.into())];
    let mut codeattach = None;
    if let Some(diff) = msg.code {
        // does the diff contain versions?
        let is_version_only = if let Some((v1, v2)) = diff::infer_version_change(&diff) {
            let lnk = create_github_compare_url(&md, (&v1, &v2));
            texts.push(lnk);
            diff::is_version_only(&diff, (&v1, &v2))
        } else {
            false
        };
        // is diff otherwise meaningful?
        if !is_version_only {
            codeattach = Some(
                AttachmentBuilder::new(diff.clone())
                    .color("#439FE0")
                    .text(vec![Text(diff.into())].as_slice())
                    .build()?,
            )
        }
    } else if let Some(v) = msg.version {
        texts.push(infer_metadata_single_link(md, v));
    }
    // Automatic CI originator link
    texts.push(infer_ci_links());
    // Auto cc users
    if let NotificationMode::NotifyMaintainers = msg.mode {
        if !md.contacts.is_empty() || !md.maintainers.is_empty() {
            texts.push(Text("<- ".to_string().into()));
        }
        // maintainer strings via people in teams.yml
        if !md.maintainers.is_empty() {
            texts.extend(maintainers_to_text_content(&md.maintainers, &owners.people))
        }
        // legacy contacts:
        if !md.contacts.is_empty() {
            texts.extend(contacts_to_text_content(&md.contacts));
        }
    }
    // Pass the texts array to slack_hook
    a = a.text(texts.as_slice());
    let mut ax = vec![a.build()?];
    // Second attachment: optional code (blue)
    if let Some(diffattach) = codeattach {
        ax.push(diffattach);
        // Pass attachment vector
    }
    p = p.attachments(ax);
    // Send everything. Phew.
    if msg.mode != NotificationMode::Silent {
        slack.send(&p.build()?).await?;
    }
    Ok(())
}
async fn send_internal ( msg : Message , chan : String , owners : & Owners ) -> Result < ( ) > { let hook_url : & str = & env_hook_url ( ) ? ; let hook_user : String = env_username ( ) ; let md = & msg . metadata ; let slack = Slack :: new ( hook_url ) ? ; let mut p = PayloadBuilder :: new ( ) . channel ( chan ) . icon_emoji ( " " ) . username ( hook_user ) ; debug ! ( " " msg ) ; // NB: cannot use .link_names due to https://api.slack.com/changelog/2017-09-the-one-about-usernames // NB: cannot use .parse(Parse::Full) as this breaks the other links // Thus we have to use full slack names, and construct SlackLink objs manually // All text is in either one or two attachments to make output as clean as possible // First attachment is main text + main link + CCs // Fallbacktext is in constructor here (shown in OSD notifies) let mut a = AttachmentBuilder :: new ( msg . text . clone ( ) ) ; // fallback if let Some ( c ) = msg . color { a = a . color ( c ) } // All text constructed for first attachment goes in this vec: let mut texts = vec ! [ Text ( msg text into ( ) ) ] ; let mut codeattach = None ; if let Some ( diff ) = msg . code { // does the diff contain versions? let is_version_only = if let Some ( ( v1 , v2 ) ) = diff :: infer_version_change ( & diff ) { let lnk = create_github_compare_url ( & md , ( & v1 , & v2 ) ) ; texts . push ( lnk ) ; diff :: is_version_only ( & diff , ( & v1 , & v2 ) ) } else { false } ; // is diff otherwise meaningful? if ! is_version_only { codeattach = Some ( AttachmentBuilder :: new ( diff . clone ( ) ) . color ( " " ) . text ( vec ! [ Text ( diff into ( ) ) ] . as_slice ( ) ) . build ( ) ? , ) } } else if let Some ( v ) = msg . version { texts . push ( infer_metadata_single_link ( md , v ) ) ; } // Automatic CI originator link texts . push ( infer_ci_links ( ) ) ; // Auto cc users if let NotificationMode :: NotifyMaintainers = msg . mode { if ! md . contacts . is_empty ( ) || ! md . maintainers . is_empty ( ) { texts . push ( Text ( " " . to_string ( ) . into ( ) ) ) ; } // maintainer strings via people in teams.yml if ! md . maintainers . is_empty ( ) { texts . extend ( maintainers_to_text_content ( & md . maintainers , & owners . people ) ) } // legacy contacts: if ! md . contacts . is_empty ( ) { texts . extend ( contacts_to_text_content ( & md . contacts ) ) ; } } // Pass the texts array to slack_hook a = a . text ( texts . as_slice ( ) ) ; let mut ax = vec ! [ a build ( ) ] ; // Second attachment: optional code (blue) if let Some ( diffattach ) = codeattach { ax . push ( diffattach ) ; // Pass attachment vector } p = p . attachments ( ax ) ; // Send everything. Phew. if msg . mode != NotificationMode :: Silent { slack . send ( & p . build ( ) ? ) . await ? ; } Ok ( ( ) ) }
Send a `Message` to a configured slack destination
Send a ` Message ` to a configured slack destination
msg
Message
chan
String
owners
&Owners
msg
Message
chan
String
owners
&Owners