MCPcopy Create free account
hub / github.com/base/base / execute

Method execute

acceptance/src/publish.rs:102–182  ·  view source on GitHub ↗

Publishes from trusted CI environment and artifact data, never executing artifact code.

(self)

Source from the content-addressed store, hash-verified

100impl PublishArgs {
101 /// Publishes from trusted CI environment and artifact data, never executing artifact code.
102 pub async fn execute(self) -> Result<()> {
103 let metadata = CommentMetadata {
104 run_id: self.run_id.clone(),
105 attempt: self.attempt,
106 started_at: self.started_at.clone(),
107 };
108 metadata.validate()?;
109 let repo = env::var("GITHUB_REPOSITORY")?;
110 let parts: Vec<_> = repo.split('/').collect();
111 ensure!(
112 parts.len() == 2
113 && parts.iter().all(|part| !part.is_empty()
114 && *part != "."
115 && *part != ".."
116 && part.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-".contains(&b))),
117 "invalid repository"
118 );
119 let tested_sha = env::var("TESTED_SHA")?;
120 PrPublisher::validate_sha(&tested_sha)?;
121 let event: Value = serde_json::from_slice(&Aggregate::bounded_read(&self.event)?)?;
122 let pr = event["pull_request"]["number"]
123 .as_u64()
124 .filter(|number| *number > 0)
125 .ok_or_else(|| eyre::eyre!("missing PR number"))?;
126 let head = event["pull_request"]["head"]["sha"].as_str().unwrap_or_default().to_owned();
127 let base = event["pull_request"]["base"]["sha"].as_str().unwrap_or_default().to_owned();
128 PrPublisher::validate_sha(&head)?;
129 PrPublisher::validate_sha(&base)?;
130 let run = self.load_result(&tested_sha).unwrap_or_else(|_| {
131 let mut run = Aggregate::fallback(
132 "Missing or invalid acceptance artifacts; inspect PR checks and report artifacts."
133 .into(),
134 );
135 run.tested_sha.clone_from(&tested_sha);
136 run.run_id.clone_from(&self.run_id);
137 run
138 });
139 let body = PrPublisher::body(
140 &run,
141 &format!("https://github.com/{repo}/pull/{pr}/checks"),
142 &metadata,
143 )?;
144 let mut authorization =
145 header::HeaderValue::from_str(&format!("Bearer {}", env::var("GITHUB_TOKEN")?))?;
146 authorization.set_sensitive(true);
147 let publisher = PrPublisher {
148 client: Client::builder()
149 .redirect(Policy::none())
150 .timeout(Duration::from_secs(20))
151 .user_agent("base-acceptance")
152 .default_headers(header::HeaderMap::from_iter([
153 (header::AUTHORIZATION, authorization),
154 (
155 header::ACCEPT,
156 header::HeaderValue::from_static("application/vnd.github+json"),
157 ),
158 (
159 header::HeaderName::from_static("x-github-api-version"),

Callers

nothing calls this directly

Calls 12

fallbackFunction · 0.85
load_resultMethod · 0.80
timeoutMethod · 0.80
okMethod · 0.80
builderFunction · 0.50
cloneMethod · 0.45
validateMethod · 0.45
collectMethod · 0.45
splitMethod · 0.45
as_strMethod · 0.45
buildMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected