Skip to content

Commit

Permalink
Merge pull request #339 from apollographql/avery/s-comitter-author
Browse files Browse the repository at this point in the history
fix: s/committer/author
  • Loading branch information
EverlastingBugstopper authored Mar 17, 2021
2 parents 6267e2b + d06c2e5 commit 41a5678
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ If present, an environment variable's value takes precedence over all other meth
| `APOLLO_VCS_REMOTE_URL` | The location of your project's repository. More info [here](#git-context) |
| `APOLLO_VCS_BRANCH` | The name of the version controlled branch. More info [here](#git-context) |
| `APOLLO_VCS_COMMIT` | The long identifier (sha in git) of the commit. More info [here](#git-context) |
| `APOLLO_VCS_COMMITTER` | The name and email of the contributor (ex. "Jane Doe \<jane@example.com\>"). More info [here](#git-context) |
| `APOLLO_VCS_AUTHOR` | The name and email of a commit's author (ex. "Jane Doe \<jane@example.com\>"). More info [here](#git-context) |


## Advanced
Expand All @@ -114,6 +114,6 @@ This information powers the ability to be able to link to a specific commit from

To see these values, just run any `check` or `publish` command with the `--log trace` option.

None of this information should be sensitive, but if you would rather overwrite these values, you may use the `APOLLO_VCS_REMOTE_URL`, `APOLLO_VCS_BRANCH`, `APOLLO_VCS_COMMIT`, and `APOLLO_VCS_COMMITTER` environment variables documented [here](./configuring#all-supported-environment-variables).
None of this information should be sensitive, but if you would rather overwrite these values, you may use the `APOLLO_VCS_REMOTE_URL`, `APOLLO_VCS_BRANCH`, `APOLLO_VCS_COMMIT`, and `APOLLO_VCS_AUTHOR` environment variables documented [here](./configuring#all-supported-environment-variables).

**Non-git users** may also use these vaiables to set similar information relevant to your VCS tool, but only git is fully supported by Apollo Studio.
2 changes: 1 addition & 1 deletion src/utils/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub enum RoverEnvKey {
VcsRemoteUrl,
VcsBranch,
VcsCommit,
VcsCommitter,
VcsAuthor,
}

impl fmt::Display for RoverEnvKey {
Expand Down
34 changes: 17 additions & 17 deletions src/utils/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use git_url_parse::GitUrl;
#[derive(Debug, PartialEq)]
pub struct GitContext {
pub branch: Option<String>,
pub committer: Option<String>,
pub author: Option<String>,
pub commit: Option<String>,
pub message: Option<String>,
pub remote_url: Option<String>,
Expand All @@ -25,15 +25,15 @@ impl GitContext {
Ok(Self {
branch: GitContext::get_branch(env, head.as_ref())?,
commit: GitContext::get_commit(env, head.as_ref())?,
committer: GitContext::get_committer(env, head.as_ref())?,
author: GitContext::get_author(env, head.as_ref())?,
remote_url: GitContext::get_remote_url(env, Some(&repo))?,
message: None,
})
}
Err(_) => Ok(Self {
branch: GitContext::get_branch(env, None)?,
commit: GitContext::get_commit(env, None)?,
committer: GitContext::get_committer(env, None)?,
author: GitContext::get_author(env, None)?,
remote_url: GitContext::get_remote_url(env, None)?,
message: None,
}),
Expand Down Expand Up @@ -62,15 +62,15 @@ impl GitContext {
}))
}

fn get_committer(env: &RoverEnv, head: Option<&Reference>) -> Result<Option<String>> {
Ok(env.get(RoverEnvKey::VcsCommitter)?.or_else(|| {
let mut committer = None;
fn get_author(env: &RoverEnv, head: Option<&Reference>) -> Result<Option<String>> {
Ok(env.get(RoverEnvKey::VcsAuthor)?.or_else(|| {
let mut author = None;
if let Some(head) = head {
if let Ok(head_commit) = head.peel_to_commit() {
committer = Some(head_commit.committer().to_string())
author = Some(head_commit.author().to_string())
}
}
committer
author
}))
}

Expand Down Expand Up @@ -137,7 +137,7 @@ impl Into<GraphPublishContextInput> for GitContext {
GraphPublishContextInput {
branch: self.branch,
commit: self.commit,
committer: self.committer,
committer: self.author,
remote_url: self.remote_url,
message: self.message,
}
Expand All @@ -150,7 +150,7 @@ impl Into<GraphCheckContextInput> for GitContext {
GraphCheckContextInput {
branch: self.branch,
commit: self.commit,
committer: self.committer,
committer: self.author,
remote_url: self.remote_url,
message: self.message,
}
Expand All @@ -164,7 +164,7 @@ impl Into<SubgraphPublishContextInput> for GitContext {
SubgraphPublishContextInput {
branch: self.branch,
commit: self.commit,
committer: self.committer,
committer: self.author,
remote_url: self.remote_url,
message: self.message,
}
Expand All @@ -177,7 +177,7 @@ impl Into<SubgraphCheckContextInput> for GitContext {
SubgraphCheckContextInput {
branch: self.branch,
commit: self.commit,
committer: self.committer,
committer: self.author,
remote_url: self.remote_url,
message: self.message,
}
Expand Down Expand Up @@ -314,19 +314,19 @@ mod tests {
#[test]
fn it_can_create_git_context_from_env() {
let branch = "mybranch".to_string();
let committer = "test subject number one".to_string();
let author = "test subject number one".to_string();
let commit = "f84b32caddddfdd9fa87d7ce2140d56eabe805ee".to_string();
let remote_url = "git@bitbucket.org:roku/theworstremoteintheworld.git".to_string();

let mut rover_env = RoverEnv::new();
rover_env.insert(RoverEnvKey::VcsBranch, &branch);
rover_env.insert(RoverEnvKey::VcsCommitter, &committer);
rover_env.insert(RoverEnvKey::VcsAuthor, &author);
rover_env.insert(RoverEnvKey::VcsCommit, &commit);
rover_env.insert(RoverEnvKey::VcsRemoteUrl, &remote_url);

let expected_git_context = GitContext {
branch: Some(branch),
committer: Some(committer),
author: Some(author),
commit: Some(commit),
message: None,
remote_url: Some(remote_url),
Expand All @@ -339,12 +339,12 @@ mod tests {
}

#[test]
fn it_can_create_git_context_committ_committer_remote_url() {
fn it_can_create_git_context_committ_author_remote_url() {
let git_context =
GitContext::try_from_rover_env(&RoverEnv::new()).expect("Could not create git context");

assert!(git_context.branch.is_some());
assert!(git_context.committer.is_some());
assert!(git_context.author.is_some());

if let Some(commit) = git_context.commit {
assert_eq!(commit.len(), 40);
Expand Down

0 comments on commit 41a5678

Please sign in to comment.