File tree Expand file tree Collapse file tree 4 files changed +21
-3
lines changed Expand file tree Collapse file tree 4 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1
1
v0.3.0 (in development)
2
2
-----------------------
3
3
- Switch from nom to winnow
4
+ - ` release ` : Take name of repository's default branch into account when adding
5
+ changelog link to README
4
6
5
7
v0.2.0 (2023-11-22)
6
8
-------------------
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ impl Release {
43
43
. context ( "Could not determine GitHub repository for local repository" ) ?;
44
44
let is_lib = package. is_lib ( ) ?;
45
45
let publish = metadata. publish . as_deref ( ) != Some ( & [ ] ) ;
46
+ let Some ( default_branch) = git. default_branch ( ) ? else {
47
+ bail ! ( "Could not determine repository's default branch" ) ;
48
+ } ;
46
49
47
50
// Determine new version
48
51
let new_version = if let Some ( v) = self . version {
@@ -270,7 +273,7 @@ impl Release {
270
273
let Some ( mut readme) = readme_file. get ( ) ? else {
271
274
bail ! ( "README.md suddenly disappeared!" ) ;
272
275
} ;
273
- if readme. ensure_changelog_link ( & ghrepo) {
276
+ if readme. ensure_changelog_link ( & ghrepo, & default_branch ) {
274
277
log:: info!( "Adding Changelog link to README.md ..." ) ;
275
278
readme_file. set ( readme) ?;
276
279
}
Original file line number Diff line number Diff line change @@ -136,6 +136,19 @@ impl<'a> Git<'a> {
136
136
}
137
137
Ok ( PathBuf :: from ( s) )
138
138
}
139
+
140
+ // Returns None if the default branch could not be determined
141
+ pub ( crate ) fn default_branch ( & self ) -> Result < Option < String > , CommandOutputError > {
142
+ let branches = self
143
+ . readlines ( "branch" , [ "--format=%(refname:short)" ] ) ?
144
+ . collect :: < HashSet < _ > > ( ) ;
145
+ for guess in [ "main" , "master" ] {
146
+ if branches. contains ( guess) {
147
+ return Ok ( Some ( guess. to_owned ( ) ) ) ;
148
+ }
149
+ }
150
+ Ok ( None )
151
+ }
139
152
}
140
153
141
154
#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -103,12 +103,12 @@ impl Readme {
103
103
}
104
104
105
105
// Returns `true` if changed
106
- pub ( crate ) fn ensure_changelog_link ( & mut self , repo : & GHRepo ) -> bool {
106
+ pub ( crate ) fn ensure_changelog_link ( & mut self , repo : & GHRepo , default_branch : & str ) -> bool {
107
107
if self . links . iter ( ) . any ( |lnk| lnk. text == "Changelog" ) {
108
108
false
109
109
} else {
110
110
self . links . push ( Link {
111
- url : format ! ( "https://github.com/{repo}/blob/master /CHANGELOG.md" ) ,
111
+ url : format ! ( "https://github.com/{repo}/blob/{default_branch} /CHANGELOG.md" ) ,
112
112
text : "Changelog" . into ( ) ,
113
113
} ) ;
114
114
true
You can’t perform that action at this time.
0 commit comments