Compare commits
21 Commits
Author | SHA1 | Date |
---|---|---|
Cadey Ratio | e94e032942 | |
Cadey Ratio | 5c48459414 | |
Cadey Ratio | 26999f5f2c | |
Cadey Ratio | 1a0bd1fcc8 | |
Cadey Ratio | 9ad6a78579 | |
Cadey Ratio | a49864c419 | |
Cadey Ratio | 7317c2425e | |
Cadey Ratio | 26894c7fad | |
Cadey Ratio | 8b55a1cfcf | |
Cadey Ratio | 613dd68f04 | |
Cadey Ratio | 8c4017a3b3 | |
Cadey Ratio | e1db8c4df4 | |
Cadey Ratio | e3a9f34178 | |
Cadey Ratio | 3846c349c4 | |
Cadey Ratio | cbf0e9d308 | |
Cadey Ratio | d5b7b59e3e | |
Cadey Ratio | 2cc49b86db | |
Cadey Ratio | bc608f7ddc | |
Cadey Ratio | 2c098d4f23 | |
Cadey Ratio | 33019d2548 | |
Cadey Ratio | 99cea1445e |
11
.drone.yml
11
.drone.yml
|
@ -3,7 +3,7 @@ name: tests/release
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: rust tests
|
- name: rust tests
|
||||||
image: "rust:1"
|
image: "reg.tulpa.dev/rust:1"
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- cargo test --all
|
- cargo test --all
|
||||||
|
@ -16,7 +16,8 @@ steps:
|
||||||
- push
|
- push
|
||||||
|
|
||||||
- name: auto-release
|
- name: auto-release
|
||||||
image: xena/gitea-release:0.3.2
|
image: xena/gitea-release
|
||||||
|
pull: always
|
||||||
settings:
|
settings:
|
||||||
auth_username: cadey
|
auth_username: cadey
|
||||||
gitea_server: https://tulpa.dev
|
gitea_server: https://tulpa.dev
|
||||||
|
@ -38,7 +39,7 @@ steps:
|
||||||
commands:
|
commands:
|
||||||
- cd elfs
|
- cd elfs
|
||||||
- cargo login $CARGO_TOKEN
|
- cargo login $CARGO_TOKEN
|
||||||
- cargo publish
|
- "cargo publish ||:"
|
||||||
environment:
|
environment:
|
||||||
CARGO_TOKEN:
|
CARGO_TOKEN:
|
||||||
from_secret: CARGO_TOKEN
|
from_secret: CARGO_TOKEN
|
||||||
|
@ -51,7 +52,7 @@ steps:
|
||||||
commands:
|
commands:
|
||||||
- cd gitea
|
- cd gitea
|
||||||
- cargo login $CARGO_TOKEN
|
- cargo login $CARGO_TOKEN
|
||||||
- cargo publish
|
- "cargo publish ||:"
|
||||||
environment:
|
environment:
|
||||||
CARGO_TOKEN:
|
CARGO_TOKEN:
|
||||||
from_secret: CARGO_TOKEN
|
from_secret: CARGO_TOKEN
|
||||||
|
@ -69,7 +70,7 @@ steps:
|
||||||
environment:
|
environment:
|
||||||
USER: root
|
USER: root
|
||||||
commands:
|
commands:
|
||||||
- cachix use xe
|
- true # cachix use xe
|
||||||
- nix-build docker.nix
|
- nix-build docker.nix
|
||||||
- cp $(readlink result) /result/docker.tgz
|
- cp $(readlink result) /result/docker.tgz
|
||||||
volumes:
|
volumes:
|
||||||
|
|
40
CHANGELOG.md
40
CHANGELOG.md
|
@ -6,6 +6,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## 0.7.1
|
||||||
|
|
||||||
|
Fix a minor parsing bug
|
||||||
|
|
||||||
|
## 0.7.0
|
||||||
|
|
||||||
|
Support reading version data from `Cargo.toml`
|
||||||
|
|
||||||
|
## 0.6.1
|
||||||
|
|
||||||
|
Fixed a logic error in release cutting.
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
Detect tags better.
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
Initialize `pretty_env_logger` on app boot. Oops.
|
||||||
|
|
||||||
|
## 0.5.0
|
||||||
|
|
||||||
|
A lot of internals to this program were exposed to external consumers. This was
|
||||||
|
used to provide an integration test.
|
||||||
|
|
||||||
|
Support for bracketed versions was added, a-la:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
## [0.1.0]
|
||||||
|
|
||||||
|
Hi there this is a test!
|
||||||
|
|
||||||
|
### ADDED
|
||||||
|
|
||||||
|
- something
|
||||||
|
```
|
||||||
|
|
||||||
|
The gitea crate was brought up to version `0.2.0` and includes a lot more
|
||||||
|
functionality.
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
This is a functionality-breaking release that removes untested/extraneous parts
|
This is a functionality-breaking release that removes untested/extraneous parts
|
||||||
|
|
|
@ -98,6 +98,17 @@ version = "0.5.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
|
checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cargo_toml"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "513d17226888c7b8283ac02a1c1b0d8a9d4cbf6db65dfadb79f598f5d7966fe9"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.54"
|
version = "1.0.54"
|
||||||
|
@ -198,6 +209,19 @@ version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca"
|
checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"humantime",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fake-simd"
|
name = "fake-simd"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
@ -323,7 +347,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gitea"
|
name = "gitea"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -335,21 +359,25 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gitea-release"
|
name = "gitea-release"
|
||||||
version = "0.3.2"
|
version = "0.7.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"cargo_toml",
|
||||||
"comrak",
|
"comrak",
|
||||||
"elfs",
|
"elfs",
|
||||||
"git2",
|
"git2",
|
||||||
"gitea",
|
"gitea",
|
||||||
"http",
|
"http",
|
||||||
"kankyo",
|
"kankyo",
|
||||||
|
"log",
|
||||||
|
"pretty_env_logger",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"structopt",
|
"structopt",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"toml",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -417,6 +445,15 @@ version = "1.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
|
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
||||||
|
dependencies = [
|
||||||
|
"quick-error",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.13.6"
|
version = "0.13.6"
|
||||||
|
@ -819,6 +856,16 @@ version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
|
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pretty_env_logger"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
|
||||||
|
dependencies = [
|
||||||
|
"env_logger",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error"
|
name = "proc-macro-error"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
@ -847,13 +894,19 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.17"
|
version = "1.0.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101"
|
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-error"
|
||||||
|
version = "1.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
|
@ -1060,18 +1113,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.111"
|
version = "1.0.117"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d"
|
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.111"
|
version = "1.0.117"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250"
|
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1169,9 +1222,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.29"
|
version = "1.0.48"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bb37da98a55b1d08529362d9cbb863be17556873df2585904ab9d2bc951291d0"
|
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1203,6 +1256,15 @@ dependencies = [
|
||||||
"winapi 0.3.8",
|
"winapi 0.3.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
@ -1304,6 +1366,15 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.5.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -1552,6 +1623,15 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.8",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gitea-release"
|
name = "gitea-release"
|
||||||
version = "0.3.2"
|
version = "0.7.1"
|
||||||
authors = ["Christine Dodrill <me@christine.website>"]
|
authors = ["Christine Dodrill <me@christine.website>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -8,15 +8,19 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
cargo_toml = "0.8.1"
|
||||||
comrak = "0.7"
|
comrak = "0.7"
|
||||||
git2 = "0.13"
|
git2 = "0.13"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
kankyo = "0.3"
|
kankyo = "0.3"
|
||||||
|
log = "0.4"
|
||||||
|
pretty_env_logger = "0"
|
||||||
reqwest = { version = "0.10", features = ["json"] }
|
reqwest = { version = "0.10", features = ["json"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
structopt = { version = "0.3", default-features = false }
|
structopt = { version = "0.3", default-features = false }
|
||||||
tokio = { version = "0.2", features = ["macros"] }
|
tokio = { version = "0.2", features = ["macros"] }
|
||||||
|
toml = "0.5.7"
|
||||||
url = "2"
|
url = "2"
|
||||||
|
|
||||||
gitea = { path = "./gitea" }
|
gitea = { path = "./gitea" }
|
||||||
|
@ -24,6 +28,7 @@ gitea = { path = "./gitea" }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
elfs = { path = "./elfs" }
|
elfs = { path = "./elfs" }
|
||||||
|
pretty_env_logger = "0.4"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gitea"
|
name = "gitea"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Christine Dodrill <me@christine.website>"]
|
authors = ["Christine Dodrill <me@christine.website>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
homepage = "https://tulpa.dev/cadey/gitea-release/src/branch/main/gitea"
|
homepage = "https://tulpa.dev/cadey/gitea-release/src/branch/main/gitea"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/// The main Gitea client. You will need an API token as described [here](https://docs.gitea.io/en-us/api-usage/).
|
/// The main Gitea client. You will need an API token as described [here](https://docs.gitea.io/en-us/api-usage/).
|
||||||
|
|
||||||
use reqwest::header;
|
use reqwest::header;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::result::Result as StdResult;
|
use std::result::Result as StdResult;
|
||||||
|
@ -70,6 +69,20 @@ pub struct Attachment {
|
||||||
pub browser_download_url: String,
|
pub browser_download_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inputs to create a gitea repo.
|
||||||
|
/// https://try.gitea.io/api/swagger#model-CreateRepoOption
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct CreateRepo {
|
||||||
|
pub auto_init: bool,
|
||||||
|
pub description: String,
|
||||||
|
pub gitignores: String,
|
||||||
|
pub issue_labels: String,
|
||||||
|
pub license: String,
|
||||||
|
pub name: String,
|
||||||
|
pub private: bool,
|
||||||
|
pub readme: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// A git repository.
|
/// A git repository.
|
||||||
/// https://try.gitea.io/api/swagger#model-Repository
|
/// https://try.gitea.io/api/swagger#model-Repository
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
@ -234,6 +247,46 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new gitea repo for the currently authenticated user with given details.
|
||||||
|
pub async fn create_user_repo(&self, cr: CreateRepo) -> Result<Repo> {
|
||||||
|
Ok(self
|
||||||
|
.cli
|
||||||
|
.post(&format!("{}/api/v1/user/repos", self.base_url))
|
||||||
|
.json(&cr)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.error_for_status()?
|
||||||
|
.json()
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new gitea repo for a given organization with given details.
|
||||||
|
pub async fn create_org_repo(&self, org: String, cr: CreateRepo) -> Result<Repo> {
|
||||||
|
Ok(self
|
||||||
|
.cli
|
||||||
|
.post(&format!("{}/api/v1/org/{}/repos", self.base_url, org))
|
||||||
|
.json(&cr)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.error_for_status()?
|
||||||
|
.json()
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deletes a gitea repo by owner and name.
|
||||||
|
pub async fn delete_repo(&self, owner: String, repo: String) -> Result<()> {
|
||||||
|
self.cli
|
||||||
|
.delete(&format!(
|
||||||
|
"{}/api/v1/repos/{}/{}",
|
||||||
|
self.base_url, owner, repo
|
||||||
|
))
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.error_for_status()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets a gitea repo by name.
|
/// Gets a gitea repo by name.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -357,4 +410,16 @@ impl Client {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns information about the currently authenticated user.
|
||||||
|
pub async fn whoami(&self) -> Result<User> {
|
||||||
|
Ok(self
|
||||||
|
.cli
|
||||||
|
.get(&format!("{}/api/v1/user", self.base_url))
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.error_for_status()?
|
||||||
|
.json()
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"owner": "nmattia",
|
"owner": "nmattia",
|
||||||
"repo": "naersk",
|
"repo": "naersk",
|
||||||
"rev": "a82fd7dc31a58c462b6dfa9d9d886fa2cc75dfd4",
|
"rev": "529e910a3f423a8211f8739290014b754b2555b6",
|
||||||
"sha256": "00bjwir52y6jbf0b22qy9qxramw35k5fc7kp9hymr1zgpmw9kbwg",
|
"sha256": "0bcy9nmyaan5jvp0wg80wkizc9j166ns685rdr1kbhkvdpywv46y",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/nmattia/naersk/archive/a82fd7dc31a58c462b6dfa9d9d886fa2cc75dfd4.tar.gz",
|
"url": "https://github.com/nmattia/naersk/archive/529e910a3f423a8211f8739290014b754b2555b6.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
},
|
},
|
||||||
"nixpkgs-mozilla": {
|
"nixpkgs-mozilla": {
|
||||||
|
@ -17,10 +17,10 @@
|
||||||
"homepage": null,
|
"homepage": null,
|
||||||
"owner": "mozilla",
|
"owner": "mozilla",
|
||||||
"repo": "nixpkgs-mozilla",
|
"repo": "nixpkgs-mozilla",
|
||||||
"rev": "e912ed483e980dfb4666ae0ed17845c4220e5e7c",
|
"rev": "efda5b357451dbb0431f983cca679ae3cd9b9829",
|
||||||
"sha256": "08fvzb8w80bkkabc1iyhzd15f4sm7ra10jn32kfch5klgl0gj3j3",
|
"sha256": "11wqrg86g3qva67vnk81ynvqyfj0zxk83cbrf0p9hsvxiwxs8469",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/mozilla/nixpkgs-mozilla/archive/e912ed483e980dfb4666ae0ed17845c4220e5e7c.tar.gz",
|
"url": "https://github.com/mozilla/nixpkgs-mozilla/archive/efda5b357451dbb0431f983cca679ae3cd9b9829.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub(crate) fn read(fname: PathBuf, tag: String) -> Result<String> {
|
||||||
|
|
||||||
let found_tag = String::from_utf8(nd.content.clone())?;
|
let found_tag = String::from_utf8(nd.content.clone())?;
|
||||||
|
|
||||||
if found_tag == tag {
|
if found_tag == tag || found_tag == format!("[{}]", tag) {
|
||||||
collect = true;
|
collect = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,7 +70,7 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn read_changelog() {
|
fn basic() {
|
||||||
let res = super::read("testdata/basic.md".into(), "0.1.0".into());
|
let res = super::read("testdata/basic.md".into(), "0.1.0".into());
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let delta = res.unwrap();
|
let delta = res.unwrap();
|
||||||
|
@ -79,4 +79,15 @@ mod tests {
|
||||||
"Hi there this is a test\\!\n### ADDED\n - something\n"
|
"Hi there this is a test\\!\n### ADDED\n - something\n"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn brackets() {
|
||||||
|
let res = super::read("testdata/brackets.md".into(), "0.1.0".into());
|
||||||
|
assert!(res.is_ok());
|
||||||
|
let delta = res.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
delta,
|
||||||
|
"Hi there this is a test\\!\n### ADDED\n - something\n"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,28 +2,26 @@ use crate::{changelog, cmd::*, git, version};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub(crate) async fn run(
|
pub async fn run(
|
||||||
common: Common,
|
common: Common,
|
||||||
fname: PathBuf,
|
fname: PathBuf,
|
||||||
tag: Option<String>,
|
tag: Option<String>,
|
||||||
rm: ReleaseMeta,
|
rm: ReleaseMeta,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let repo = git2::Repository::open(".")?;
|
let repo = git2::Repository::open(".")?;
|
||||||
let tag = tag.unwrap_or(version::read_version("VERSION".into())?);
|
let tag = tag.unwrap_or(version::read("VERSION".into())?);
|
||||||
let desc = changelog::read(fname.clone(), tag.clone())?;
|
let vtag = format!("v{}", tag);
|
||||||
|
|
||||||
if !git::has_tag(&repo, tag.clone())? {
|
if git::has_tag(&repo, vtag.clone())? {
|
||||||
git::tag_version(&repo, tag.clone(), desc.clone())?;
|
println!("release {} already released", vtag);
|
||||||
let _ = git::push_tags(&repo);
|
|
||||||
} else
|
|
||||||
/* The tag already exists */
|
|
||||||
{
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let desc = changelog::read(fname, tag.clone())?;
|
let desc = changelog::read(fname, tag.clone())?;
|
||||||
let cli = gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT)?;
|
let cli = gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT)?;
|
||||||
let vtag = format!("v{}", tag);
|
let repo = cli
|
||||||
|
.get_repo(common.owner.clone(), common.repo.clone())
|
||||||
|
.await?;
|
||||||
|
|
||||||
let cr = gitea::CreateRelease {
|
let cr = gitea::CreateRelease {
|
||||||
body: desc,
|
body: desc,
|
||||||
|
@ -31,7 +29,7 @@ pub(crate) async fn run(
|
||||||
name: rm.name.or(Some(format!("Version {}", tag))).unwrap(),
|
name: rm.name.or(Some(format!("Version {}", tag))).unwrap(),
|
||||||
prerelease: rm.pre_release,
|
prerelease: rm.pre_release,
|
||||||
tag_name: vtag,
|
tag_name: vtag,
|
||||||
target_commitish: "HEAD".into(),
|
target_commitish: repo.default_branch,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = cli.create_release(common.owner, common.repo, cr).await?;
|
let _ = cli.create_release(common.owner, common.repo, cr).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use anyhow::Result;
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub(crate) async fn run(env: DroneEnv) -> Result<()> {
|
pub async fn run(env: DroneEnv) -> Result<()> {
|
||||||
let common: Common = env.clone().into();
|
let common: Common = env.clone().into();
|
||||||
|
|
||||||
let default_branch = {
|
let default_branch = {
|
||||||
|
|
|
@ -1,40 +1,55 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
pub(crate) mod cut;
|
pub mod cut;
|
||||||
pub(crate) mod drone_plugin;
|
pub mod drone_plugin;
|
||||||
|
|
||||||
#[derive(StructOpt, Debug, Clone)]
|
#[derive(StructOpt, Debug, Clone)]
|
||||||
pub(crate) struct Common {
|
pub struct Common {
|
||||||
/// The gitea server to connect to
|
/// The gitea server to connect to
|
||||||
#[structopt(short, long, env = "GITEA_SERVER")]
|
#[structopt(short, long, env = "GITEA_SERVER")]
|
||||||
pub server: String,
|
pub server: String,
|
||||||
|
|
||||||
/// The gitea token to authenticate with
|
/// The gitea token to authenticate with
|
||||||
#[structopt(long, env = "GITEA_TOKEN")]
|
#[structopt(long, env = "GITEA_TOKEN")]
|
||||||
pub token: String,
|
pub token: String,
|
||||||
|
|
||||||
/// The gitea user to authenticate as
|
/// The gitea user to authenticate as
|
||||||
#[structopt(short, long, env = "GITEA_AUTH_USER")]
|
#[structopt(short, long, env = "GITEA_AUTH_USER")]
|
||||||
pub auth_user: String,
|
pub auth_user: String,
|
||||||
|
|
||||||
/// The owner of the gitea repo
|
/// The owner of the gitea repo
|
||||||
#[structopt(short, long, env = "GITEA_OWNER")]
|
#[structopt(short, long, env = "GITEA_OWNER")]
|
||||||
pub owner: String,
|
pub owner: String,
|
||||||
|
|
||||||
/// The gitea repo to operate on
|
/// The gitea repo to operate on
|
||||||
#[structopt(short, long, env = "GITEA_REPO")]
|
#[structopt(short, long, env = "GITEA_REPO")]
|
||||||
pub repo: String,
|
pub repo: String,
|
||||||
|
|
||||||
|
/// Git signature email
|
||||||
|
#[structopt(long, short = "E", env = "SIGNATURE_EMAIL", default_value = "domo@tulpa.dev")]
|
||||||
|
pub email: String,
|
||||||
|
|
||||||
|
/// Git signature username
|
||||||
|
#[structopt(long, short = "U", env = "SIGNATURE_NAME", default_value = "Domo Arigato")]
|
||||||
|
pub username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug, Clone)]
|
#[derive(StructOpt, Debug, Clone)]
|
||||||
pub(crate) struct DroneEnv {
|
pub struct DroneEnv {
|
||||||
// Given by drone
|
// Given by drone
|
||||||
/// push URL
|
/// push URL
|
||||||
#[structopt(long, env = "DRONE_GIT_HTTP_URL")]
|
#[structopt(long, env = "DRONE_GIT_HTTP_URL")]
|
||||||
pub push_url: String,
|
pub push_url: String,
|
||||||
|
|
||||||
/// repo owner
|
/// repo owner
|
||||||
#[structopt(long, env = "DRONE_REPO_OWNER")]
|
#[structopt(long, env = "DRONE_REPO_OWNER")]
|
||||||
pub owner: String,
|
pub owner: String,
|
||||||
|
|
||||||
/// repo name
|
/// repo name
|
||||||
#[structopt(long, env = "DRONE_REPO_NAME")]
|
#[structopt(long, env = "DRONE_REPO_NAME")]
|
||||||
pub repo: String,
|
pub repo: String,
|
||||||
|
|
||||||
/// branch
|
/// branch
|
||||||
#[structopt(long, env = "DRONE_REPO_BRANCH")]
|
#[structopt(long, env = "DRONE_REPO_BRANCH")]
|
||||||
pub branch: String,
|
pub branch: String,
|
||||||
|
@ -43,18 +58,30 @@ pub(crate) struct DroneEnv {
|
||||||
/// auth username
|
/// auth username
|
||||||
#[structopt(long, env = "PLUGIN_AUTH_USERNAME")]
|
#[structopt(long, env = "PLUGIN_AUTH_USERNAME")]
|
||||||
pub auth_user: String,
|
pub auth_user: String,
|
||||||
|
|
||||||
/// Gitea server
|
/// Gitea server
|
||||||
#[structopt(long, env = "PLUGIN_GITEA_SERVER")]
|
#[structopt(long, env = "PLUGIN_GITEA_SERVER")]
|
||||||
pub server: String,
|
pub server: String,
|
||||||
|
|
||||||
/// Gitea token
|
/// Gitea token
|
||||||
#[structopt(long, env = "PLUGIN_GITEA_TOKEN")]
|
#[structopt(long, env = "PLUGIN_GITEA_TOKEN")]
|
||||||
pub token: String,
|
pub token: String,
|
||||||
|
|
||||||
/// CHANGELOG path
|
/// CHANGELOG path
|
||||||
#[structopt(long, env = "PLUGIN_CHANGELOG_PATH", default_value = "./CHANGELOG.md")]
|
#[structopt(long, env = "PLUGIN_CHANGELOG_PATH", default_value = "./CHANGELOG.md")]
|
||||||
pub changelog_path: PathBuf,
|
pub changelog_path: PathBuf,
|
||||||
|
|
||||||
/// Default branch name
|
/// Default branch name
|
||||||
#[structopt(long, env = "PLUGIN_DEFAULT_BRANCH")]
|
#[structopt(long, env = "PLUGIN_DEFAULT_BRANCH")]
|
||||||
pub default_branch: Option<String>,
|
pub default_branch: Option<String>,
|
||||||
|
|
||||||
|
/// Git signature email
|
||||||
|
#[structopt(long, short = "E", env = "PLUGIN_SIGNATURE_EMAIL", default_value = "domo@tulpa.dev")]
|
||||||
|
pub email: String,
|
||||||
|
|
||||||
|
/// Git signature username
|
||||||
|
#[structopt(long, short = "U", env = "PLUGIN_SIGNATURE_NAME", default_value = "Domo Arigato")]
|
||||||
|
pub username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Common> for DroneEnv {
|
impl Into<Common> for DroneEnv {
|
||||||
|
@ -65,12 +92,14 @@ impl Into<Common> for DroneEnv {
|
||||||
auth_user: self.auth_user,
|
auth_user: self.auth_user,
|
||||||
owner: self.owner,
|
owner: self.owner,
|
||||||
repo: self.repo,
|
repo: self.repo,
|
||||||
|
email: self.email,
|
||||||
|
username: self.username,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
pub(crate) struct ReleaseMeta {
|
pub struct ReleaseMeta {
|
||||||
/// Release name
|
/// Release name
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long)]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
@ -84,7 +113,7 @@ pub(crate) struct ReleaseMeta {
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(about = "Gitea release assistant")]
|
#[structopt(about = "Gitea release assistant")]
|
||||||
pub(crate) enum Cmd {
|
pub enum Cmd {
|
||||||
/// Create a new tag and release on Gitea
|
/// Create a new tag and release on Gitea
|
||||||
#[structopt(alias = "release")]
|
#[structopt(alias = "release")]
|
||||||
Cut {
|
Cut {
|
||||||
|
|
78
src/git.rs
78
src/git.rs
|
@ -1,22 +1,67 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use git2::{Repository, Signature};
|
use git2::{
|
||||||
|
Cred, CredentialType, Direction, FetchOptions, PushOptions, RemoteCallbacks, Repository,
|
||||||
|
Signature,
|
||||||
|
};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
pub(crate) fn push_tags(repo: &Repository) -> Result<()> {
|
pub const TAGS: &'static [&'static str] = &["refs/tags/*:refs/tags/*"];
|
||||||
|
|
||||||
|
pub fn pull(repo: &Repository, token: String, what: &[&str]) -> Result<()> {
|
||||||
let mut remote = repo.find_remote("origin")?;
|
let mut remote = repo.find_remote("origin")?;
|
||||||
remote.connect(git2::Direction::Push)?;
|
let mut fo = FetchOptions::new();
|
||||||
remote.push(&["refs/tags/*:refs/tags/*"], None)?;
|
|
||||||
|
remote.connect_auth(Direction::Fetch, Some(callbacks(token.clone())), None)?;
|
||||||
|
fo.remote_callbacks(callbacks(token));
|
||||||
|
remote.fetch(what, Some(&mut fo), None)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tag_version(repo: &Repository, tag: String, desc: String) -> Result<()> {
|
fn callbacks<'a>(token: String) -> RemoteCallbacks<'a> {
|
||||||
let sig = &Signature::now("Gitea Release Tool", "gitea-release@tulpa.dev")?;
|
let mut callbacks = RemoteCallbacks::new();
|
||||||
|
callbacks.credentials(move |_u, _username, allowed_types| {
|
||||||
|
if allowed_types.contains(CredentialType::SSH_KEY) {
|
||||||
|
let user = "git";
|
||||||
|
Cred::ssh_key_from_agent(user)
|
||||||
|
} else {
|
||||||
|
Cred::userpass_plaintext(&token, "x-oauth-basic")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callbacks
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push(repo: &Repository, token: String, what: &[&str]) -> Result<()> {
|
||||||
|
let mut remote = repo.find_remote("origin")?;
|
||||||
|
|
||||||
|
remote.connect_auth(Direction::Push, Some(callbacks(token.clone())), None)?;
|
||||||
|
|
||||||
|
let mut po = PushOptions::new();
|
||||||
|
po.remote_callbacks(callbacks(token));
|
||||||
|
remote.push(what, Some(&mut po))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commit(repo: &Repository, sig: &Signature, msg: &str, files: &[&str]) -> Result<()> {
|
||||||
|
let mut index = repo.index()?;
|
||||||
|
for file in files {
|
||||||
|
index.add_path(Path::new(file))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let oid = index.write_tree()?;
|
||||||
|
let tree = repo.find_tree(oid)?;
|
||||||
|
repo.commit(Some("HEAD"), &sig, &sig, &msg, &tree, &[])?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tag_version(repo: &Repository, sig: &Signature, tag: String, desc: String) -> Result<()> {
|
||||||
let obj = repo.revparse_single("HEAD")?;
|
let obj = repo.revparse_single("HEAD")?;
|
||||||
repo.tag(&tag, &obj, &sig, &desc, false)?;
|
repo.tag(&tag, &obj, &sig, &desc, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn has_tag(repo: &Repository, tag: String) -> Result<bool> {
|
pub fn has_tag(repo: &Repository, tag: String) -> Result<bool> {
|
||||||
let tags = repo.tag_names(Some(&tag))?;
|
let tags = repo.tag_names(Some(&tag))?;
|
||||||
|
|
||||||
for tag_obj in tags.iter() {
|
for tag_obj in tags.iter() {
|
||||||
|
@ -25,6 +70,7 @@ pub(crate) fn has_tag(repo: &Repository, tag: String) -> Result<bool> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let tag_name = tag_obj.unwrap();
|
let tag_name = tag_obj.unwrap();
|
||||||
|
log::debug!("tag: {}", tag_name.to_string());
|
||||||
if tag == tag_name.to_string() {
|
if tag == tag_name.to_string() {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +83,7 @@ pub(crate) fn has_tag(repo: &Repository, tag: String) -> Result<bool> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use git2::*;
|
use git2::*;
|
||||||
use std::{fs::File, io::Write, path::Path};
|
use std::{fs::File, io::Write};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -48,22 +94,10 @@ mod tests {
|
||||||
let mut fout = File::create(&dir.path().join("VERSION"))?;
|
let mut fout = File::create(&dir.path().join("VERSION"))?;
|
||||||
write!(fout, "{}", TAG)?;
|
write!(fout, "{}", TAG)?;
|
||||||
drop(fout);
|
drop(fout);
|
||||||
let mut index = repo.index()?;
|
|
||||||
index.add_path(Path::new("VERSION"))?;
|
|
||||||
let oid = index.write_tree()?;
|
|
||||||
let tree = repo.find_tree(oid)?;
|
|
||||||
|
|
||||||
let sig = &Signature::now("Gitea Release Tool", "gitea-release@tulpa.dev")?;
|
let sig = &Signature::now("Gitea Release Tool", "gitea-release@tulpa.dev")?;
|
||||||
repo.commit(
|
super::commit(&repo, &sig, "test commit please ignore", &["VERSION"])?;
|
||||||
Some("HEAD"),
|
super::tag_version(&repo, &sig, TAG.into(), format!("version {}", TAG))?;
|
||||||
&sig,
|
|
||||||
&sig,
|
|
||||||
"test commit please ignore",
|
|
||||||
&tree,
|
|
||||||
&[],
|
|
||||||
)?;
|
|
||||||
|
|
||||||
super::tag_version(&repo, TAG.into(), format!("version {}", TAG))?;
|
|
||||||
assert!(super::has_tag(&repo, TAG.into())?);
|
assert!(super::has_tag(&repo, TAG.into())?);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
pub mod changelog;
|
||||||
|
pub mod cmd;
|
||||||
|
pub mod git;
|
||||||
|
pub mod version;
|
||||||
|
|
||||||
|
// Name your user agent after your app?
|
||||||
|
pub static APP_USER_AGENT: &str =
|
||||||
|
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
14
src/main.rs
14
src/main.rs
|
@ -1,21 +1,13 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
mod changelog;
|
use ::gitea_release::{cmd::{self, Cmd}};
|
||||||
mod cmd;
|
|
||||||
mod git;
|
|
||||||
mod version;
|
|
||||||
|
|
||||||
pub(crate) use cmd::*;
|
|
||||||
|
|
||||||
// Name your user agent after your app?
|
|
||||||
pub(crate) static APP_USER_AGENT: &str =
|
|
||||||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let _ = kankyo::init();
|
let _ = kankyo::init();
|
||||||
let cmd = cmd::Cmd::from_args();
|
pretty_env_logger::init();
|
||||||
|
let cmd = Cmd::from_args();
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
Cmd::Cut {
|
Cmd::Cut {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use std::{fs, path::PathBuf};
|
|
||||||
|
|
||||||
pub(crate) fn read_version(fname: PathBuf) -> Result<String> {
|
|
||||||
let version = fs::read_to_string(fname)?;
|
|
||||||
Ok(version.trim().into())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn read_version() {
|
|
||||||
let version = super::read_version("./testdata/VERSION".into()).unwrap();
|
|
||||||
assert_eq!(version, "0.1.0");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use cargo_toml::Manifest;
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
fn get_file_as_byte_vec(filename: &str) -> Option<Vec<u8>> {
|
||||||
|
let f = File::open(&filename);
|
||||||
|
if f.is_err() {
|
||||||
|
log::debug!("can't read from Cargo.toml: {:?}", f.unwrap_err());
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let mut f = f.unwrap();
|
||||||
|
let metadata = fs::metadata(&filename).expect("unable to read metadata");
|
||||||
|
let mut buffer = vec![0; metadata.len() as usize];
|
||||||
|
f.read(&mut buffer).expect("buffer overflow");
|
||||||
|
|
||||||
|
Some(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read() -> Result<Option<String>> {
|
||||||
|
log::debug!("reading version from Cargo.toml");
|
||||||
|
let bytes = get_file_as_byte_vec("Cargo.toml");
|
||||||
|
log::debug!("{:?}", bytes);
|
||||||
|
|
||||||
|
match bytes {
|
||||||
|
Some(bytes) => {
|
||||||
|
log::trace!("reading toml");
|
||||||
|
let pkg : Result<Manifest, _> = toml::from_slice(&bytes);
|
||||||
|
match pkg {
|
||||||
|
Err(why) => {
|
||||||
|
log::error!("error parsing Cargo.toml: {:?}", why);
|
||||||
|
Err(why.into())
|
||||||
|
}
|
||||||
|
Ok(pkg) => {
|
||||||
|
let version = pkg.package.unwrap().version;
|
||||||
|
log::trace!("got version {}", version);
|
||||||
|
Ok(Some(version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn read() {
|
||||||
|
use super::read;
|
||||||
|
let _ = pretty_env_logger::try_init();
|
||||||
|
read().unwrap().unwrap();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
|
mod cargo;
|
||||||
|
|
||||||
|
pub(crate) fn read(fname: PathBuf) -> Result<String> {
|
||||||
|
let version = match read_fs(fname.clone()) {
|
||||||
|
Ok(version) => version,
|
||||||
|
Err(why) => {
|
||||||
|
log::debug!("can't read {:?}: {:?}", fname, why);
|
||||||
|
cargo::read().unwrap().unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(version)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_fs(fname: PathBuf) -> Result<String> {
|
||||||
|
log::debug!("reading version data from {:?}", fname);
|
||||||
|
Ok(fs::read_to_string(fname)?.trim().into())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn read_version() {
|
||||||
|
let _ = pretty_env_logger::try_init();
|
||||||
|
let version = super::read_fs("./testdata/VERSION".into()).unwrap();
|
||||||
|
assert_eq!(version, "0.1.0");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
## [0.1.0]
|
||||||
|
Hi there this is a test!
|
||||||
|
### ADDED
|
||||||
|
- something
|
|
@ -0,0 +1,96 @@
|
||||||
|
use ::gitea_release::{cmd, git, APP_USER_AGENT};
|
||||||
|
use anyhow::Result;
|
||||||
|
use git2::{Repository, Signature};
|
||||||
|
use log::debug;
|
||||||
|
use std::{fs::File, io::Write};
|
||||||
|
|
||||||
|
const TAG: &'static str = "0.1.0";
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cut() -> Result<()> {
|
||||||
|
let _ = pretty_env_logger::try_init();
|
||||||
|
let name = elfs::next();
|
||||||
|
let token = std::env::var("DOMO_GITEA_TOKEN").expect("wanted envvar DOMO_GITEA_TOKEN");
|
||||||
|
|
||||||
|
let cli = gitea::Client::new("https://tulpa.dev".into(), token.clone(), APP_USER_AGENT)?;
|
||||||
|
debug!("created gitea client");
|
||||||
|
|
||||||
|
let gitea_repo = cli
|
||||||
|
.create_user_repo(gitea::CreateRepo {
|
||||||
|
auto_init: false,
|
||||||
|
description: format!("https://tulpa.dev/cadey/gitea-release test repo"),
|
||||||
|
gitignores: "".into(),
|
||||||
|
issue_labels: "".into(),
|
||||||
|
license: "".into(),
|
||||||
|
name: name.clone(),
|
||||||
|
private: true,
|
||||||
|
readme: "".into(),
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
debug!("created repo domo/{}", name);
|
||||||
|
|
||||||
|
let dir = tempfile::tempdir()?;
|
||||||
|
let repo = Repository::init(&dir)?;
|
||||||
|
let sig = &Signature::now("Domo Arigato", "domo@tulpa.dev")?;
|
||||||
|
debug!("initialized repo in {:?}", dir.path());
|
||||||
|
|
||||||
|
let mut fout = File::create(&dir.path().join("VERSION"))?;
|
||||||
|
write!(fout, "{}", TAG)?;
|
||||||
|
drop(fout);
|
||||||
|
|
||||||
|
let mut fout = File::create(&dir.path().join("CHANGELOG.md"))?;
|
||||||
|
fout.write_all(include_bytes!("../testdata/basic.md"))?;
|
||||||
|
drop(fout);
|
||||||
|
|
||||||
|
git::commit(&repo, &sig, TAG.into(), &["VERSION", "CHANGELOG.md"])?;
|
||||||
|
debug!("committed files");
|
||||||
|
|
||||||
|
repo.remote("origin", &gitea_repo.clone_url)?;
|
||||||
|
debug!("set up origin remote to {}", gitea_repo.clone_url);
|
||||||
|
|
||||||
|
git::push(
|
||||||
|
&repo,
|
||||||
|
token.clone(),
|
||||||
|
&["refs/heads/master:refs/heads/master"],
|
||||||
|
)?;
|
||||||
|
debug!("pushed to {} with token {}", gitea_repo.clone_url, token);
|
||||||
|
|
||||||
|
std::env::set_current_dir(dir.path())?;
|
||||||
|
cmd::cut::run(
|
||||||
|
cmd::Common {
|
||||||
|
server: "https://tulpa.dev".into(),
|
||||||
|
token: token,
|
||||||
|
auth_user: gitea_repo.owner.login.clone(),
|
||||||
|
owner: gitea_repo.owner.login.clone(),
|
||||||
|
repo: gitea_repo.name,
|
||||||
|
email: "domo@tulpa.dev".into(),
|
||||||
|
username: "Domo Arigato".into(),
|
||||||
|
},
|
||||||
|
"CHANGELOG.md".into(),
|
||||||
|
None,
|
||||||
|
cmd::ReleaseMeta {
|
||||||
|
name: None,
|
||||||
|
draft: false,
|
||||||
|
pre_release: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let rls = cli
|
||||||
|
.get_release_by_tag(
|
||||||
|
gitea_repo.owner.login.clone(),
|
||||||
|
name.clone(),
|
||||||
|
format!("v{}", TAG),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
rls.body,
|
||||||
|
"Hi there this is a test\\!\n### ADDED\n - something\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
cli.delete_repo(gitea_repo.owner.login, name).await?;
|
||||||
|
debug!("deleted repo {}", gitea_repo.clone_url);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue