compiler-cli
compiler-core
src
docs
package_interface
snapshots
···
8
8
use gleam_core::{
9
9
Error,
10
10
build::Runtime,
11
11
-
config::{DenoConfig, DenoFlag, Docs, ErlangConfig, JavaScriptConfig, Repository},
11
11
+
config::{DenoConfig, DenoFlag, Docs, ErlangConfig, JavaScriptConfig},
12
12
manifest::{Base16Checksum, Manifest, ManifestPackage, ManifestPackageSource},
13
13
requirement::Requirement,
14
14
};
···
1176
1176
documentation: Docs { pages: vec![] },
1177
1177
dependencies,
1178
1178
dev_dependencies,
1179
1179
-
repository: Repository::None,
1179
1179
+
repository: None,
1180
1180
links: vec![],
1181
1181
erlang: ErlangConfig {
1182
1182
application_start_module: None,
···
107
107
);
108
108
109
109
// Prompt the user to make a git tag if they have not.
110
110
-
let has_repo = config.repository.url().is_some();
110
110
+
let has_repo = config.repository.is_some();
111
111
let git = PathBuf::from(".git");
112
112
-
let tag_name = config.repository.tag_for_version(&config.version);
112
112
+
let tag_name = config.tag_for_version(&config.version);
113
113
let git_tag = git.join("refs").join("tags").join(&tag_name);
114
114
if has_repo && git.exists() && !git_tag.exists() {
115
115
println!(
···
207
207
}
208
208
209
209
fn check_repo_url(config: &PackageConfig, i_am_sure: bool) -> Result<bool, Error> {
210
210
-
let Some(url) = config.repository.url() else {
210
210
+
let Some(repo) = config.repository.as_ref() else {
211
211
return Ok(true);
212
212
};
213
213
+
let url = repo.url();
213
214
214
215
let runtime = tokio::runtime::Runtime::new().expect("Unable to start Tokio async runtime");
215
216
let response = runtime.block_on(reqwest::get(&url)).map_err(Error::http)?;
···
443
444
source_files: &[Utf8PathBuf],
444
445
generated_files: &[(Utf8PathBuf, String)],
445
446
) -> Result<String> {
446
446
-
let repo_url = http::Uri::try_from(config.repository.url().unwrap_or_default()).ok();
447
447
+
let repo_url = http::Uri::try_from(
448
448
+
config
449
449
+
.repository
450
450
+
.as_ref()
451
451
+
.map(|r| r.url())
452
452
+
.unwrap_or_default(),
453
453
+
)
454
454
+
.ok();
447
455
let requirements: Result<Vec<ReleaseRequirement<'a>>> = config
448
456
.dependencies
449
457
.iter()
···
152
152
#[serde(default, rename = "dev-dependencies", serialize_with = "ordered_map")]
153
153
pub dev_dependencies: Dependencies,
154
154
#[serde(default)]
155
155
-
pub repository: Repository,
155
155
+
pub repository: Option<Repository>,
156
156
#[serde(default)]
157
157
pub links: Vec<Link>,
158
158
#[serde(default)]
···
298
298
}
299
299
}
300
300
Ok(())
301
301
+
}
302
302
+
303
303
+
pub fn tag_for_version(&self, version: &Version) -> String {
304
304
+
let prefix = match self.repository.as_ref() {
305
305
+
Some(
306
306
+
Repository::GitHub { tag_prefix, .. }
307
307
+
| Repository::GitLab { tag_prefix, .. }
308
308
+
| Repository::BitBucket { tag_prefix, .. }
309
309
+
| Repository::Codeberg { tag_prefix, .. }
310
310
+
| Repository::SourceHut { tag_prefix, .. }
311
311
+
| Repository::Gitea { tag_prefix, .. }
312
312
+
| Repository::Forgejo { tag_prefix, .. },
313
313
+
) => tag_prefix.as_ref(),
314
314
+
315
315
+
Some(Repository::Custom { .. }) | None => None,
316
316
+
};
317
317
+
318
318
+
match prefix {
319
319
+
Some(prefix) => format!("{prefix}v{version}"),
320
320
+
None => format!("v{version}"),
321
321
+
}
301
322
}
302
323
}
303
324
···
763
784
}
764
785
765
786
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
766
766
-
#[serde(tag = "type", rename_all = "lowercase")]
787
787
+
#[serde(tag = "type")]
767
788
pub enum Repository {
789
789
+
#[serde(rename = "github")]
768
790
GitHub {
769
791
user: String,
770
792
repo: String,
771
793
path: Option<String>,
794
794
+
#[serde(rename = "tag-prefix")]
772
795
tag_prefix: Option<String>,
773
796
},
797
797
+
#[serde(rename = "gitlab")]
774
798
GitLab {
775
799
user: String,
776
800
repo: String,
777
801
path: Option<String>,
802
802
+
#[serde(rename = "tag-prefix")]
778
803
tag_prefix: Option<String>,
779
804
},
805
805
+
#[serde(rename = "bitbucket")]
780
806
BitBucket {
781
807
user: String,
782
808
repo: String,
783
809
path: Option<String>,
810
810
+
#[serde(rename = "tag-prefix")]
784
811
tag_prefix: Option<String>,
785
812
},
813
813
+
#[serde(rename = "codeberg")]
786
814
Codeberg {
787
815
user: String,
788
816
repo: String,
789
817
path: Option<String>,
818
818
+
#[serde(rename = "tag-prefix")]
790
819
tag_prefix: Option<String>,
791
820
},
792
792
-
#[serde(alias = "forgejo")]
821
821
+
#[serde(rename = "gitea")]
793
822
Gitea {
794
823
user: String,
795
824
repo: String,
796
825
path: Option<String>,
826
826
+
#[serde(rename = "tag-prefix")]
797
827
tag_prefix: Option<String>,
798
828
#[serde(
799
829
serialize_with = "uri_serde::serialize",
···
801
831
)]
802
832
host: Uri,
803
833
},
834
834
+
#[serde(rename = "forgejo")]
835
835
+
Forgejo {
836
836
+
user: String,
837
837
+
repo: String,
838
838
+
path: Option<String>,
839
839
+
#[serde(rename = "tag-prefix")]
840
840
+
tag_prefix: Option<String>,
841
841
+
#[serde(
842
842
+
serialize_with = "uri_serde::serialize",
843
843
+
deserialize_with = "uri_serde_default_https::deserialize"
844
844
+
)]
845
845
+
host: Uri,
846
846
+
},
847
847
+
#[serde(rename = "sourcehut")]
804
848
SourceHut {
805
849
user: String,
806
850
repo: String,
807
851
path: Option<String>,
852
852
+
#[serde(rename = "tag-prefix")]
808
853
tag_prefix: Option<String>,
809
854
},
855
855
+
#[serde(rename = "custom")]
810
856
Custom {
811
857
url: String,
858
858
+
#[serde(rename = "tag-prefix")]
859
859
+
tag_prefix: Option<String>,
812
860
},
813
813
-
None,
814
861
}
815
862
816
863
impl Repository {
817
817
-
pub fn url(&self) -> Option<String> {
864
864
+
pub fn url(&self) -> String {
818
865
match self {
819
866
Repository::GitHub { repo, user, .. } => {
820
820
-
Some(format!("https://github.com/{user}/{repo}"))
867
867
+
format!("https://github.com/{user}/{repo}")
821
868
}
822
869
Repository::GitLab { repo, user, .. } => {
823
823
-
Some(format!("https://gitlab.com/{user}/{repo}"))
870
870
+
format!("https://gitlab.com/{user}/{repo}")
824
871
}
825
872
Repository::BitBucket { repo, user, .. } => {
826
826
-
Some(format!("https://bitbucket.com/{user}/{repo}"))
873
873
+
format!("https://bitbucket.com/{user}/{repo}")
827
874
}
828
875
Repository::Codeberg { repo, user, .. } => {
829
829
-
Some(format!("https://codeberg.org/{user}/{repo}"))
876
876
+
format!("https://codeberg.org/{user}/{repo}")
830
877
}
831
878
Repository::SourceHut { repo, user, .. } => {
832
832
-
Some(format!("https://git.sr.ht/~{user}/{repo}"))
879
879
+
format!("https://git.sr.ht/~{user}/{repo}")
833
880
}
834
881
Repository::Gitea {
835
882
repo, user, host, ..
883
883
+
}
884
884
+
| Repository::Forgejo {
885
885
+
repo, user, host, ..
836
886
} => {
837
887
let string_host = host.to_string();
838
888
let cleaned_host = string_host.trim_end_matches('/');
839
839
-
Some(format!("{cleaned_host}/{user}/{repo}"))
889
889
+
format!("{cleaned_host}/{user}/{repo}")
840
890
}
841
841
-
Repository::Custom { url } => Some(url.clone()),
842
842
-
Repository::None => None,
891
891
+
Repository::Custom { url, .. } => url.clone(),
843
892
}
844
893
}
845
894
···
850
899
| Repository::BitBucket { path, .. }
851
900
| Repository::Codeberg { path, .. }
852
901
| Repository::SourceHut { path, .. }
853
853
-
| Repository::Gitea { path, .. } => path.as_ref(),
854
854
-
855
855
-
Repository::Custom { .. } | Repository::None => None,
856
856
-
}
857
857
-
}
858
858
-
859
859
-
pub fn tag_for_version(&self, version: &Version) -> String {
860
860
-
let prefix = match self {
861
861
-
Repository::GitHub { tag_prefix, .. }
862
862
-
| Repository::GitLab { tag_prefix, .. }
863
863
-
| Repository::BitBucket { tag_prefix, .. }
864
864
-
| Repository::Codeberg { tag_prefix, .. }
865
865
-
| Repository::SourceHut { tag_prefix, .. }
866
866
-
| Repository::Gitea { tag_prefix, .. } => tag_prefix.as_ref(),
867
867
-
868
868
-
Repository::Custom { .. } | Repository::None => None,
869
869
-
};
902
902
+
| Repository::Gitea { path, .. }
903
903
+
| Repository::Forgejo { path, .. } => path.as_ref(),
870
904
871
871
-
match prefix {
872
872
-
Some(prefix) => format!("{prefix}{version}"),
873
873
-
None => format!("v{version}"),
905
905
+
Repository::Custom { .. } => None,
874
906
}
875
875
-
}
876
876
-
}
877
877
-
878
878
-
impl Default for Repository {
879
879
-
fn default() -> Self {
880
880
-
Self::None
881
907
}
882
908
}
883
909
···
101
101
path: doc_link.href.to_string(),
102
102
});
103
103
104
104
-
let repo_link = config.repository.url().map(|path| Link {
105
105
-
name: "Repository".into(),
106
106
-
path,
107
107
-
});
104
104
+
let repo_link = config
105
105
+
.repository
106
106
+
.as_ref()
107
107
+
.map(|r| r.url())
108
108
+
.map(|path| Link {
109
109
+
name: "Repository".into(),
110
110
+
path,
111
111
+
});
108
112
109
113
let host = if is_hex_publish == DocContext::HexPublish {
110
114
"https://hexdocs.pm"
···
26
26
.expect("path is not in root")
27
27
.with_extension("gleam");
28
28
29
29
-
let path_in_repo = match project_config.repository.path() {
29
29
+
let path_in_repo = match project_config
30
30
+
.repository
31
31
+
.as_ref()
32
32
+
.map(|r| r.path())
33
33
+
.unwrap_or_default()
34
34
+
{
30
35
Some(repo_path) => to_url_path(&Utf8PathBuf::from(repo_path).join(path)),
31
36
_ => to_url_path(&path),
32
37
}
33
38
.unwrap_or_default();
34
39
35
35
-
let tag = project_config
40
40
+
let tag = project_config.tag_for_version(&project_config.version);
41
41
+
42
42
+
let url_pattern = project_config
36
43
.repository
37
37
-
.tag_for_version(&project_config.version);
38
38
-
39
39
-
let url_pattern = match &project_config.repository {
40
40
-
Repository::GitHub { user, repo, .. } => Some((
41
41
-
format!("https://github.com/{user}/{repo}/blob/{tag}/{path_in_repo}#L"),
42
42
-
"-L".into(),
43
43
-
)),
44
44
-
Repository::GitLab { user, repo, .. } => Some((
45
45
-
format!("https://gitlab.com/{user}/{repo}/-/blob/{tag}/{path_in_repo}#L"),
46
46
-
"-".into(),
47
47
-
)),
48
48
-
Repository::BitBucket { user, repo, .. } => Some((
49
49
-
format!("https://bitbucket.com/{user}/{repo}/src/{tag}/{path_in_repo}#lines-"),
50
50
-
":".into(),
51
51
-
)),
52
52
-
Repository::Codeberg { user, repo, .. } => Some((
53
53
-
format!("https://codeberg.org/{user}/{repo}/src/tag/{tag}/{path_in_repo}#L"),
54
54
-
"-".into(),
55
55
-
)),
56
56
-
Repository::SourceHut { user, repo, .. } => Some((
57
57
-
format!("https://git.sr.ht/~{user}/{repo}/tree/{tag}/item/{path_in_repo}#L"),
58
58
-
"-".into(),
59
59
-
)),
60
60
-
Repository::Gitea {
61
61
-
user, repo, host, ..
62
62
-
} => {
63
63
-
let string_host = host.to_string();
64
64
-
let cleaned_host = string_host.trim_end_matches('/');
65
65
-
Some((
66
66
-
format!("{cleaned_host}/{user}/{repo}/src/tag/{tag}/{path_in_repo}#L",),
44
44
+
.as_ref()
45
45
+
.map(|r| match r {
46
46
+
Repository::GitHub { user, repo, .. } => Some((
47
47
+
format!("https://github.com/{user}/{repo}/blob/{tag}/{path_in_repo}#L"),
48
48
+
"-L".into(),
49
49
+
)),
50
50
+
Repository::GitLab { user, repo, .. } => Some((
51
51
+
format!("https://gitlab.com/{user}/{repo}/-/blob/{tag}/{path_in_repo}#L"),
67
52
"-".into(),
68
68
-
))
69
69
-
}
70
70
-
Repository::Custom { .. } | Repository::None => None,
71
71
-
};
53
53
+
)),
54
54
+
Repository::BitBucket { user, repo, .. } => Some((
55
55
+
format!("https://bitbucket.com/{user}/{repo}/src/{tag}/{path_in_repo}#lines-"),
56
56
+
":".into(),
57
57
+
)),
58
58
+
Repository::Codeberg { user, repo, .. } => Some((
59
59
+
format!("https://codeberg.org/{user}/{repo}/src/tag/{tag}/{path_in_repo}#L"),
60
60
+
"-".into(),
61
61
+
)),
62
62
+
Repository::SourceHut { user, repo, .. } => Some((
63
63
+
format!("https://git.sr.ht/~{user}/{repo}/tree/{tag}/item/{path_in_repo}#L"),
64
64
+
"-".into(),
65
65
+
)),
66
66
+
Repository::Gitea {
67
67
+
user, repo, host, ..
68
68
+
}
69
69
+
| Repository::Forgejo {
70
70
+
user, repo, host, ..
71
71
+
} => {
72
72
+
let string_host = host.to_string();
73
73
+
let cleaned_host = string_host.trim_end_matches('/');
74
74
+
Some((
75
75
+
format!("{cleaned_host}/{user}/{repo}/src/tag/{tag}/{path_in_repo}#L",),
76
76
+
"-".into(),
77
77
+
))
78
78
+
}
79
79
+
Repository::Custom { .. } => None,
80
80
+
})
81
81
+
.unwrap_or_default();
72
82
73
83
SourceLinker {
74
84
line_numbers: LineNumbers::new(&module.code),
···
618
618
fn source_link_for_github_repository() {
619
619
let mut config = PackageConfig::default();
620
620
config.name = EcoString::from("test_project_name");
621
621
-
config.repository = Repository::GitHub {
621
621
+
config.repository = Some(Repository::GitHub {
622
622
user: "wibble".to_string(),
623
623
repo: "wobble".to_string(),
624
624
path: None,
625
625
tag_prefix: None,
626
626
-
};
626
626
+
});
627
627
628
628
let modules = vec![("app.gleam", "pub type Wibble = Int")];
629
629
assert!(
···
636
636
fn source_link_for_github_repository_with_path_and_tag_prefix() {
637
637
let mut config = PackageConfig::default();
638
638
config.name = EcoString::from("test_project_name");
639
639
-
config.repository = Repository::GitHub {
639
639
+
config.repository = Some(Repository::GitHub {
640
640
user: "wibble".to_string(),
641
641
repo: "wobble".to_string(),
642
642
path: Some("path/to/package".to_string()),
643
643
-
tag_prefix: Some("subdir-v".into()),
644
644
-
};
643
643
+
tag_prefix: Some("subdir-".into()),
644
644
+
});
645
645
646
646
let modules = vec![("app.gleam", "pub type Wibble = Int")];
647
647
assert!(compile(config, modules).contains(
···
1168
1168
1169
1169
#[test]
1170
1170
fn gitea_repository_url_has_no_double_slash() {
1171
1171
-
let repo = Repository::Gitea {
1171
1171
+
let repo = Repository::Forgejo {
1172
1172
host: "https://code.example.org/".parse::<Uri>().unwrap(),
1173
1173
user: "person".into(),
1174
1174
repo: "forgejo_bug".into(),
1175
1175
path: None,
1176
1176
+
tag_prefix: None,
1176
1177
};
1177
1178
1178
1178
-
assert_eq!(
1179
1179
-
repo.url().unwrap(),
1180
1180
-
"https://code.example.org/person/forgejo_bug"
1181
1181
-
);
1179
1179
+
assert_eq!(repo.url(), "https://code.example.org/person/forgejo_bug");
1182
1180
}
1183
1181
1184
1182
#[test]
···
8
8
use crate::{
9
9
analyse::TargetSupport,
10
10
build::{Module, Origin, Package, Target},
11
11
-
config::{Docs, ErlangConfig, GleamVersion, JavaScriptConfig, PackageConfig, Repository},
11
11
+
config::{Docs, ErlangConfig, GleamVersion, JavaScriptConfig, PackageConfig},
12
12
line_numbers::LineNumbers,
13
13
type_::PRELUDE_MODULE_NAME,
14
14
uid::UniqueIdGenerator,
···
162
162
documentation: Docs { pages: vec![] },
163
163
dependencies: std::collections::HashMap::new(),
164
164
dev_dependencies: std::collections::HashMap::new(),
165
165
-
repository: Repository::default(),
165
165
+
repository: None,
166
166
links: vec![],
167
167
erlang: ErlangConfig::default(),
168
168
javascript: JavaScriptConfig::default(),
···
1
1
---
2
2
source: compiler-core/src/config.rs
3
3
+
assertion_line: 1116
3
4
expression: output
5
5
+
snapshot_kind: text
4
6
---
5
7
--- GLEAM.TOML
6
8
···
21
23
},
22
24
"dependencies": {},
23
25
"dev-dependencies": {},
24
24
-
"repository": {
25
25
-
"type": "none"
26
26
-
},
26
26
+
"repository": null,
27
27
"links": [],
28
28
"erlang": {
29
29
"application_start_module": null,
···
1
1
---
2
2
source: compiler-core/src/config.rs
3
3
+
assertion_line: 1106
3
4
expression: output
5
5
+
snapshot_kind: text
4
6
---
5
7
--- GLEAM.TOML
6
8
···
78
80
"user": "example",
79
81
"repo": "my_dep",
80
82
"path": null,
81
81
-
"tag_prefix": null
83
83
+
"tag-prefix": null
82
84
},
83
85
"links": [
84
86
{
···
1
1
---
2
2
source: compiler-core/src/docs.rs
3
3
+
assertion_line: 785
3
4
expression: output
5
5
+
snapshot_kind: text
4
6
---
5
7
--- GLEAM.TOML
6
8
···
22
24
},
23
25
"dependencies": {},
24
26
"dev-dependencies": {},
25
25
-
"repository": {
26
26
-
"type": "none"
27
27
-
},
27
27
+
"repository": null,
28
28
"links": [],
29
29
"erlang": {
30
30
"application_start_module": null,
···
1
1
---
2
2
source: compiler-core/src/docs.rs
3
3
+
assertion_line: 765
3
4
expression: output
5
5
+
snapshot_kind: text
4
6
---
5
7
--- GLEAM.TOML
6
8
···
79
81
"user": "example",
80
82
"repo": "my_dep",
81
83
"path": null,
82
82
-
"tag_prefix": null
84
84
+
"tag-prefix": null
83
85
},
84
86
"links": [
85
87
{