1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright (c) 2017 repomon-config developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.

//! Configuration management for repomon.
//!
//! # Examples
//!
//! ## Read from TOML string
//!
//! ```
//! # #[macro_use] extern crate error_chain;
//! # extern crate repomon_config;
//! # extern crate toml;
//! #
//! # use repomon_config::{read_toml, Branches};
//! # use std::io::Cursor;
//! #
//! # mod error {
//! #     error_chain!{
//! #         foreign_links {
//! #             Io(::std::io::Error);
//! #             RepomonConfig(::repomon_config::Error);
//! #             TomlDe(::toml::de::Error);
//! #             TomlSer(::toml::ser::Error);
//! #         }
//! #     }
//! # }
//! #
//! # fn main() {}
//! #
//! # fn read() -> error::Result<()> {
//!     let test_toml = r#"[[branch.blah]]
//!     name = "origin/master"
//!     interval = "1m"
//!
//!     [[branch.repomon]]
//!     name = "origin/master"
//!     interval = "1m"
//!
//!     [[branch.repomon]]
//!     name = "origin/feature/testing"
//!     interval = "1m"
//!
//!     [[branch.repomon-config]]
//!     name = "origin/master"
//!     interval = "1m"
//!     "#;
//!
//!     // Serialize the TOML above into a `Branches` struct.
//!     let mut reader = Cursor::new(test_toml);
//!     let branches = read_toml(&mut reader)?;
//!
//!     // Check the `Branches` struct.
//!     let branch_map = branches.branch_map();
//!     assert_eq!(branch_map.keys().len(), 3);
//!     assert!(branch_map.contains_key("repomon"));
//!     assert!(branch_map.contains_key("repomon-config"));
//!     assert!(branch_map.contains_key("blah"));
//!
//!     // Check we have the right number of branch definitions per repo.
//!     let mut branches = branch_map.get("repomon").ok_or("invalid key")?;
//!     assert_eq!(branches.len(), 2);
//!     branches = branch_map.get("repomon-config").ok_or("invalid key")?;
//!     assert_eq!(branches.len(), 1);
//!     branches = branch_map.get("blah").ok_or("invalid key")?;
//!     assert_eq!(branches.len(), 1);
//! #   Ok(())
//! # }
//! ```
//!
//! ## Write to TOML string
//!
//! ```
//! # #[macro_use] extern crate error_chain;
//! # extern crate repomon_config;
//! # extern crate toml;
//! #
//! # use repomon_config::{write_toml, Branch, Branches};
//! # use std::collections::BTreeMap;
//! # use std::io::Cursor;
//! #
//! # mod error {
//! #     error_chain!{
//! #         foreign_links {
//! #             Io(::std::io::Error);
//! #             RepomonConfig(::repomon_config::Error);
//! #             TomlDe(::toml::de::Error);
//! #             TomlSer(::toml::ser::Error);
//! #         }
//! #     }
//! # }
//! #
//! # const TEST_TOML: &str = r#"[[branch.blah]]
//! # name = "origin/master"
//! # interval = "1m"
//! #
//! # [[branch.repomon]]
//! # name = "origin/master"
//! # interval = "1m"
//! #
//! # [[branch.repomon]]
//! # name = "origin/feature/testing"
//! # interval = "1m"
//! #
//! # [[branch.repomon-config]]
//! # name = "origin/master"
//! # interval = "1m"
//! # "#;
//! #
//! # fn main() {}
//! #
//! # fn write() -> error::Result<()> {
//!       // Setup the `Branches` struct.
//!       let mut master: Branch = Default::default();
//!       master.set_name("origin/master".to_string());
//!       master.set_interval("1m".to_string());
//!
//!       let mut feature_testing: Branch = Default::default();
//!       feature_testing.set_name("origin/feature/testing".to_string());
//!       feature_testing.set_interval("1m".to_string());
//!
//!       let repomon_branches = vec![master.clone(), feature_testing];
//!       let blah_branches = vec![master.clone()];
//!       let repomon_config_branches = vec![master];
//!
//!       let mut branch_map = BTreeMap::new();
//!       branch_map.insert("repomon".to_string(), repomon_branches);
//!       branch_map.insert("repomon-config".to_string(), repomon_config_branches);
//!       branch_map.insert("blah".to_string(), blah_branches);
//!
//!       let mut branches: Branches = Default::default();
//!       branches.set_branch_map(branch_map);
//!
//!       // Write the TOML to the given buf.
//!       let mut buf = [0; 5000];
//!
//!       // Wrapped to drop mutable borrow.
//!       {
//!         let mut writer = Cursor::new(&mut buf[..]);
//!         write_toml(&branches, &mut writer)?;
//!       }
//!
//!       // Check that the result is the same as the TOML above.
//!       assert_eq!(TEST_TOML, String::from_utf8_lossy(&buf));
//! #   Ok(())
//! # }
//! ```
//!
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate getset;
#[macro_use]
extern crate serde_derive;

#[cfg(test)]
extern crate bincode;
extern crate toml;

pub use config::{read_toml, write_toml, Branch, Branches};
pub use error::{Error, ErrorKind};
pub use message::Message;

mod config;
mod error;
mod message;