-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Adding ability to specify attachment in Node script command…
… line and starting on Gradle plugin attachment publishing
- Loading branch information
Showing
57 changed files
with
437 additions
and
3,898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...shers/gradle-plugin/src/main/groovy/projektor/plugin/attachments/AttachmentsClient.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package projektor.plugin.attachments | ||
|
||
import okhttp3.MediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.RequestBody | ||
import okhttp3.Response | ||
import org.gradle.api.logging.Logger | ||
import projektor.plugin.client.ClientConfig | ||
|
||
import static projektor.plugin.client.ClientToken.conditionallyAddPublishTokenToRequest | ||
|
||
class AttachmentsClient { | ||
private final OkHttpClient client | ||
private final ClientConfig config | ||
private final Logger logger | ||
|
||
AttachmentsClient(OkHttpClient client, ClientConfig clientConfig, Logger logger) { | ||
this.client = client | ||
this.config = clientConfig | ||
this.logger = logger | ||
} | ||
|
||
void sendAttachmentToServer(String publicId, File attachment) { | ||
MediaType mediaType = MediaType.get("octet/stream") | ||
|
||
RequestBody body = RequestBody.create(mediaType, attachment.bytes) | ||
|
||
String attachmentUrl = "${config.serverUrl}/run/${publicId}/attachments/${attachment.name}" | ||
Request.Builder requestBuilder = new Request.Builder() | ||
.url(attachmentUrl) | ||
.post(body) | ||
conditionallyAddPublishTokenToRequest(requestBuilder, config) | ||
Request request = requestBuilder.build() | ||
|
||
Response response = null | ||
|
||
try { | ||
response = client.newCall(request).execute() | ||
} catch (Exception e) { | ||
logger.error("Error uploading attachment to Projektor ${attachmentUrl}", e) | ||
} | ||
|
||
if (!response?.successful) { | ||
String responseCode = response ? "- response code ${response.code()}" : "" | ||
logger.warn("Failed to upload attachment to Projektor report ${attachmentUrl} ${responseCode}") | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...plugin/results/ResultsClientConfig.groovy → ...ojektor/plugin/client/ClientConfig.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
publishers/gradle-plugin/src/main/groovy/projektor/plugin/client/ClientToken.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package projektor.plugin.client | ||
|
||
import okhttp3.Request | ||
|
||
class ClientToken { | ||
static final String PUBLISH_TOKEN_NAME = "X-PROJEKTOR-TOKEN" | ||
|
||
static void conditionallyAddPublishTokenToRequest(Request.Builder requestBuilder, ClientConfig config) { | ||
config.maybePublishToken.ifPresent( { publishToken -> requestBuilder.header(PUBLISH_TOKEN_NAME, publishToken)}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
publishers/gradle-plugin/src/test/groovy/projektor/plugin/AttachmentsWireMockStubber.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package projektor.plugin | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.verification.LoggedRequest | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse | ||
import static com.github.tomakehurst.wiremock.client.WireMock.post | ||
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching | ||
|
||
class AttachmentsWireMockStubber extends WireMockStubber { | ||
AttachmentsWireMockStubber(WireMockServer wireMockServer) { | ||
super(wireMockServer) | ||
} | ||
|
||
void stubAttachmentPostSuccess(String publicId, String attachmentName) { | ||
wireMockServer.stubFor(post(urlEqualTo("/run/${publicId}/attachments/${attachmentName}")).willReturn(aResponse() | ||
.withStatus(200))) | ||
} | ||
|
||
List<LoggedRequest> findAttachmentsRequests(String publicId) { | ||
wireMockServer.findRequestsMatching( | ||
postRequestedFor(urlMatching("/run/${publicId}/attachments/.*")).build() | ||
).requests | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
publishers/gradle-plugin/src/test/groovy/projektor/plugin/ResultsWireMockStubber.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package projektor.plugin | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.http.Fault | ||
import com.github.tomakehurst.wiremock.verification.LoggedRequest | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse | ||
import static com.github.tomakehurst.wiremock.client.WireMock.post | ||
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo | ||
|
||
class ResultsWireMockStubber extends WireMockStubber { | ||
ResultsWireMockStubber(WireMockServer wireMockServer) { | ||
super(wireMockServer) | ||
} | ||
|
||
void stubResultsPostSuccess(String resultsId) { | ||
wireMockServer.stubFor(post(urlEqualTo("/groupedResults")).willReturn(aResponse() | ||
.withStatus(200) | ||
.withBody("""{"id": "${resultsId}", "uri": "/tests/${resultsId}"}"""))) | ||
} | ||
|
||
void stubResultsPostFailure(int statusCode) { | ||
wireMockServer.stubFor(post(urlEqualTo("/groupedResults")).willReturn(aResponse() | ||
.withStatus(statusCode))) | ||
} | ||
|
||
void stubResultsNetworkingError() { | ||
wireMockServer.stubFor(post(urlEqualTo("/groupedResults")).willReturn(aResponse() | ||
.withFault(Fault.CONNECTION_RESET_BY_PEER) | ||
)) | ||
} | ||
|
||
List<LoggedRequest> findResultsRequests() { | ||
wireMockServer.findRequestsMatching( | ||
postRequestedFor(urlEqualTo("/groupedResults")).build() | ||
).requests | ||
} | ||
} |
Oops, something went wrong.