Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: s/committer/author #339

Merged
merged 5 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \<[email protected]\>"). More info [here](#git-context) |
| `APOLLO_VCS_AUTHOR` | The name and email of a commit's author (ex. "Jane Doe \<[email protected]\>"). 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 `push` 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<GraphPushContextInput> for GitContext {
GraphPushContextInput {
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 @@ -163,7 +163,7 @@ impl Into<SubgraphPushContextInput> for GitContext {
SubgraphPushContextInput {
branch: self.branch,
commit: self.commit,
committer: self.committer,
committer: self.author,
remote_url: self.remote_url,
message: self.message,
}
Expand All @@ -176,7 +176,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 @@ -313,19 +313,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 = "[email protected]: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 @@ -338,12 +338,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