Expand readme, correct Authorization http header
parent
8d0c7813f5
commit
ca4580790b
File diff suppressed because it is too large
Load Diff
|
@ -8,10 +8,15 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
rusqlite = { version="0.20.0", features=["uuid",]}
|
||||
melib = { git= "https://git.meli.delivery/meli/meli", branch = "master" }
|
||||
uuid = "*"
|
||||
time = "*"
|
||||
serde_json = "1.0.40"
|
||||
serde= { version = "1.0.101", features = ["derive"]}
|
||||
reqwest = "0.9.20"
|
||||
toml = "0.5.3"
|
||||
|
||||
[dependencies.melib]
|
||||
git = "https://git.meli.delivery/meli/meli"
|
||||
version = "0.3.2"
|
||||
default-features = false
|
||||
features = []
|
||||
|
|
68
README.md
68
README.md
|
@ -1,4 +1,4 @@
|
|||
# issue_bot
|
||||
# `issue_bot`
|
||||
|
||||
A bot to handle bug reports through mail, for gitea's issue tracker.
|
||||
|
||||
|
@ -24,7 +24,7 @@ The bot looks for a `config.toml` file in the same directory as the binary. The
|
|||
# the tag that prefixes email subjects eg "[issue-bot-issues] blah blah"
|
||||
tag = "issue-bot-issues"
|
||||
# the auth_token for the gitea's instance API
|
||||
auth_token= "Basic ________________________________________________________________________________________________________________________________________________________________"
|
||||
auth_token= "7a36300555aaf84a0af9847e9747a0df72a82056"
|
||||
# the local part of your bot's receiving address.
|
||||
local_part= "issues"
|
||||
domain= "meli.delivery"
|
||||
|
@ -33,13 +33,73 @@ repo = "meli/issue-bot"
|
|||
bot_name = "IssueBot"
|
||||
bot_username = "issue_bot"
|
||||
# the shell command that the bot pipes mail to
|
||||
mailer = "cat"
|
||||
# mailer = "cat" # just print the e-mail in stdout
|
||||
# mailer = "/usr/sbin/sendmail -t webmaster@meli.delivery" # send copies to an address
|
||||
mailer = "/usr/sbin/sendmail -t"
|
||||
```
|
||||
|
||||
Setup your mail server to deliver mail with destination `{local_part}+tags@{domain}` to this binary. Simply call the binary and write the email in UTF-8 in the binary's standard input.
|
||||
|
||||
Setup a periodic check in your preferred task scheduler to run `issue_bot_bin cron` in order to fetch replies to issues.
|
||||
On postfix this can be done by creating a transport map and a pipe. A transport map is a file that tells postfix to send mails send to `{local_part}` to a specific program. The pipe will be this program.
|
||||
|
||||
Open `master.cf` and paste this line at the bottom:
|
||||
|
||||
```text
|
||||
issue_bot unix - n n - - pipe
|
||||
user=issuebot directory=/path/to/binarydir/ argv=/path/to/binary
|
||||
```
|
||||
|
||||
an example:
|
||||
|
||||
|
||||
```text
|
||||
issue_bot unix - n n - - pipe
|
||||
user=issuebot directory=/home/issuebot/ argv=/home/issuebot/issue-bot
|
||||
```
|
||||
|
||||
Then create your transport map:
|
||||
|
||||
```text
|
||||
{local_part}@{domain} issue_bot:
|
||||
```
|
||||
|
||||
Notice the colon at the end. This means that it refers to a transfer, not an address. Save the file somewhere (eg `/etc/postfix/issue_transport`) and make it readable by postfix. Issue `postmap /etcpostfix/issue_transport`. Finally add the entry `hash:/etc/postfix/issue_transport` in your `transport_maps` and `local_recipient_maps` keys in `main.cf`. `postfix reload` to load the configuration changes.
|
||||
|
||||
You will also need the following setting to allow tags in your recipient addresses:
|
||||
|
||||
```text
|
||||
recipient_delimiter = +
|
||||
```
|
||||
|
||||
Setup a periodic check in your preferred task scheduler to run `issue_bot_bin cron` in order to fetch replies to issues. On systemd this can be done with timers.
|
||||
|
||||
|
||||
### Troubleshooting
|
||||
If you your email stops working or postfix doesn't pass mail to the bot, make sure you're not using a non-default setup like virtual mailboxes. In that case you have to add the transport along with the transports of your setup, whatever that be.
|
||||
|
||||
If the e-mail gets to the binary and nothing happens, make sure:
|
||||
|
||||
- the binary is executable and readable by the pipe's user
|
||||
- the configuration file is in the same directory as the binary
|
||||
- that in `master.cf` there are no `flags=` in the transport entry. The mail must be piped unaltered.
|
||||
- your auth token works. You can check yourself by issuing requests to your API via cURL. There are examples here: https://docs.gitea.io/en-us/api-usage/
|
||||
|
||||
If commands (using +reply, +close etc) don't work, make sure you have added `recipient_delimiter = +` in your `main.cf` file.
|
||||
|
||||
The bot's state is saved in a sqlite3 database in the same directory as the binary. You can view its data by using the `sqlite3` cli tool:
|
||||
|
||||
```shell
|
||||
root# sqlite3 /home/issuebot/sqlite3.db
|
||||
SQLite version ****** ********** ********
|
||||
Enter ".help" for usage hints.
|
||||
sqlite> .tables
|
||||
issue
|
||||
sqlite> select * from issue;
|
||||
1|Name <add@res.tld>|1F:|2019-09-29T12:20:21.658495173Z|0|1|issue title|"2019-09-29T15:20:21+03:00"
|
||||
2|Name <add@res.tld>|{^D0u|2019-09-29T12:23:48.291970808Z|0|1|issue title#2|"2019-09-29T15:23:48+03:00"
|
||||
3|Name <add@res.tld>|Gd)i]|2019-09-29T12:24:31.414792595Z|0|1|issue title again|"2019-09-29T15:26:53+03:00"
|
||||
4|Name <add@res.tld>|$3fBוv|2019-09-29T12:28:21.187425505Z|1|1|many issues|"2019-09-29T15:28:21+03:00"
|
||||
```
|
||||
## Demo
|
||||
|
||||
My email:
|
||||
|
|
|
@ -42,7 +42,7 @@ pub fn new_issue(
|
|||
.replace("{base_url}", &conf.base_url)
|
||||
.replace("{repo}", &conf.repo),
|
||||
)
|
||||
.header("authorization", &conf.auth_token)
|
||||
.header("Authorization", format!("token {}", &conf.auth_token))
|
||||
.json(&issue)
|
||||
.send()
|
||||
.unwrap()
|
||||
|
@ -109,7 +109,7 @@ pub fn new_reply(
|
|||
.replace("{repo}", &conf.repo)
|
||||
.replace("{index}", &results[0].0.to_string()),
|
||||
)
|
||||
.header("authorization", &conf.auth_token)
|
||||
.header("Authorization", format!("token {}", &conf.auth_token))
|
||||
.json(&CreateIssueCommentOption {
|
||||
body: format!(
|
||||
"{} replies:\n\n{}",
|
||||
|
@ -164,7 +164,7 @@ pub fn close(conn: &Connection, password: Password, conf: &Config) -> Result<(St
|
|||
.replace("{repo}", &conf.repo),
|
||||
&results[0].0.to_string()
|
||||
))
|
||||
.header("authorization", &conf.auth_token)
|
||||
.header("Authorization", format!("token {}", &conf.auth_token))
|
||||
.json(&EditIssueOption {
|
||||
state: "closed".to_string(),
|
||||
})
|
||||
|
@ -236,7 +236,7 @@ pub fn comments(
|
|||
.replace("{repo}", &conf.repo)
|
||||
.replace("{index}", &id.to_string()),
|
||||
)
|
||||
.header("authorization", &conf.auth_token)
|
||||
.header("Authorization", format!("token {}", &conf.auth_token))
|
||||
.query(&[("since", since)])
|
||||
.send()
|
||||
.unwrap()
|
||||
|
|
Loading…
Reference in New Issue