Skip to content

Commit c71b4de

Browse files
authored
Merge pull request #95 from Kobzol/remove-master-dependency
Remove hardcoded master references for rust-lang/rust
2 parents 061b45a + 8cd1f7c commit c71b4de

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

local/run.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set -euo pipefail
77
IFS=$'\n\t'
88

99
RUSTC_REPO="https://github.com/rust-lang/rust"
10-
RUSTC_DEFAULT_BRANCH="master"
1110

1211
# CDN to download CI artifacts from.
1312
DOWNLOAD_BASE="https://ci-artifacts.rust-lang.org/rustc-builds"
@@ -47,17 +46,17 @@ override_commit="$2"
4746

4847
# Nightly is on the default branch
4948
if [[ "${channel}" = "nightly" ]]; then
50-
branch="${RUSTC_DEFAULT_BRANCH}"
49+
branch="HEAD"
5150
else
52-
branch="${channel}"
51+
branch="refs/heads/${channel}"
5352
fi
5453

5554
echo "==> overriding files to force promote-release to run"
5655
mc cp "/src/local/channel-rust-${channel}.toml" "local/static/dist/channel-rust-${channel}.toml" >/dev/null
5756

5857
if [[ "${override_commit}" = "" ]]; then
5958
echo "==> detecting the last rustc commit on branch ${branch}"
60-
commit="$(git ls-remote "${RUSTC_REPO}" | grep "refs/heads/${branch}" | awk '{print($1)}')"
59+
commit="$(git ls-remote "${RUSTC_REPO}" "${branch}" | awk '{print($1)}')"
6160
else
6261
echo "=>> using overridden commit ${override_commit}"
6362
commit="${override_commit}"

src/branching.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ impl Context {
1818
return Ok(());
1919
};
2020
let mut token = github.token("rust-lang/rust")?;
21-
let bump_commit = branchpoint(&mut token, "master")?;
21+
let repo = token.repository()?;
22+
let bump_commit = branchpoint(&mut token, &repo.default_branch)?;
2223
let prebump_sha = bump_commit.parents[0].sha.clone();
2324
let beta_sha = token.get_ref("heads/beta")?;
2425

src/github.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,19 @@ impl RepositoryClient<'_> {
411411
self.client.without_body().send_with_response::<GitFile>()
412412
}
413413

414+
/// Returns information about the current repository
415+
pub(crate) fn repository(&mut self) -> anyhow::Result<Repository> {
416+
self.start_new_request()?;
417+
self.client.get(true)?;
418+
self.client.url(&format!(
419+
"https://api.github.com/repos/{repo}",
420+
repo = self.repo,
421+
))?;
422+
self.client
423+
.without_body()
424+
.send_with_response::<Repository>()
425+
}
426+
414427
pub(crate) fn merge_pr(&mut self, pr: u32) -> anyhow::Result<()> {
415428
self.start_new_request()?;
416429
self.client.put(true)?;
@@ -496,6 +509,11 @@ impl GitFile {
496509
}
497510
}
498511

512+
#[derive(Debug, serde::Deserialize)]
513+
pub(crate) struct Repository {
514+
pub(crate) default_branch: String,
515+
}
516+
499517
#[derive(Copy, Clone)]
500518
pub(crate) struct CreateTag<'a> {
501519
pub(crate) commit: &'a str,

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ impl Context {
104104
return Ok(commit);
105105
}
106106

107-
let git_ref = match self.config.channel {
108-
Channel::Nightly => "refs/heads/master",
109-
Channel::Beta => "refs/heads/beta",
110-
Channel::Stable => "refs/heads/stable",
111-
};
112-
113107
// git2 requires a git repository to be able to connect to a remote and fetch metadata, so
114108
// this creates an empty repository in a temporary directory. It will be deleted once the
115109
// function returns.
@@ -119,6 +113,12 @@ impl Context {
119113
let mut remote = repo.remote("origin", &self.config.repository)?;
120114
remote.connect(git2::Direction::Fetch)?;
121115

116+
let git_ref = match self.config.channel {
117+
Channel::Nightly => remote.default_branch()?.as_str().unwrap().to_string(),
118+
Channel::Beta => "refs/heads/beta".to_string(),
119+
Channel::Stable => "refs/heads/stable".to_string(),
120+
};
121+
122122
for head in remote.list()? {
123123
if head.name() == git_ref {
124124
return Ok(hex::encode(head.oid().as_bytes()));

0 commit comments

Comments
 (0)