Commit

Agents move along on private repositories too

The lifecycle, acceptance checks, reviews and the files a pull request changes all read the repository as the pull request's author. Authors are stored without their memberships, so on a private repository the repository looked missing and nothing moved: no review, no revision, no checks, no overlaps. They now read it as the author with membership of the repository's workspace.

syntaqxcommitted Parent8d40168Browse files
4 files+29−60/4 viewed
+1−1
110110 };
111111
112112 // The author can read both the repository and the pull request's source.
113− let viewer = Some(pull.author.clone());
113+ let viewer = self.author_viewer(&pull).await?;
114114 let repo: Outcome<Repo> = g1t_kit::call(
115115 &self.repos,
116116 "get_by_id",
+22−0
116116 .await
117117 }
118118
119+ /// A pull request's author as a viewer who can read its repository and
120+ /// source. Stored authors carry no memberships, so a private repository
121+ /// would otherwise look missing to them.
122+ pub(crate) async fn author_viewer(&self, pull: &Pull) -> Result<Viewer> {
123+ let path: Option<RepoPath> = g1t_kit::call(
124+ &self.repos,
125+ "path_by_id",
126+ &g1t_contracts::repos::PathByIdArgs { id: pull.repo_id.clone() },
127+ )
128+ .await?;
129+ let mut author = pull.author.clone();
130+ if let Some(path) = path
131+ && !author.is_member(&path.namespace.to_lowercase())
132+ {
133+ author.workspaces.push(g1t_contracts::Membership {
134+ slug: path.namespace.to_lowercase(),
135+ role: g1t_contracts::Role::Member,
136+ });
137+ }
138+ Ok(Some(author))
139+ }
140+
119141 /// Publishes an event caused by `actor`, or by g1t itself.
120142 async fn publish_as<T: Serialize>(
121143 &self,
+4−3
739739 if pull.status != PullStatus::Open {
740740 return Ok(Advance::None);
741741 }
742− // Its author can read both the repository and the fork.
743− let viewer: Viewer = Some(pull.author.clone());
742+ // As a member: a private repository would look missing otherwise,
743+ // and the pull request would never move.
744+ let viewer: Viewer = self.author_viewer(&pull).await?;
744745 let repo: Outcome<Repo> = g1t_kit::call(
745746 &self.repos,
746747 "get_by_id",
10521053 "get_by_id",
10531054 &GetByIdArgs {
10541055 id: pull.repo_id.clone(),
1055− viewer: Some(pull.author.clone()),
1056+ viewer: self.author_viewer(&pull).await?,
10561057 },
10571058 )
10581059 .await?;
+2−2
6363 /// every one of them each time.
6464 pub(crate) async fn refresh_files(&self, pull: &Pull) -> Result<Vec<ChangedFile>> {
6565 // Its author can read both the repository and the pull request's source.
66− let viewer = Some(pull.author.clone());
66+ let viewer = self.author_viewer(pull).await?;
6767 let compared: Outcome<Comparison> =
6868 g1t_kit::call(&self.repos, "compare", &pull.comparison(&viewer)).await?;
6969 let files: Vec<ChangedFile> = match compared {
180180 "A pull request can be reviewed once it is ready for review.",
181181 ));
182182 }
183− let viewer = Some(pull.author.clone());
183+ let viewer = self.author_viewer(&pull).await?;
184184 let repo: Outcome<Repo> = g1t_kit::call(
185185 &self.repos,
186186 "get_by_id",