Skip to content

Commit 565f07e

Browse files
authored
ci: add formatting CI (GoogleCloudPlatform#122)
* ci: add formatting CI Use Google formatting guidelines to format existing code. * Merge with lint workflow and add formatting instructions to CONTRIBUTING.md
1 parent 5df7444 commit 565f07e

File tree

30 files changed

+798
-668
lines changed

30 files changed

+798
-668
lines changed

.github/workflows/lint.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches:
55
- master
66
pull_request:
7+
workflow_dispatch:
78
jobs:
89
lint:
910
runs-on: ubuntu-latest
@@ -20,4 +21,20 @@ jobs:
2021
- name: Build Invoker with Maven
2122
run: (cd functions-framework-api/ && mvn install)
2223
- name: Lint Invoker
23-
run: (cd invoker/ && mvn clean verify -DskipTests -P lint)
24+
run: (cd invoker/ && mvn clean verify -DskipTests -P lint)
25+
formatting:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v2 # v2 minimum required
29+
- name: Run formatter
30+
id: formatter
31+
uses: axel-op/googlejavaformat-action@v3
32+
with:
33+
args: "--dry-run --set-exit-if-changed"
34+
continue-on-error: true
35+
- name: Check for failure
36+
if: steps.formatter.outcome != 'success'
37+
run: |
38+
echo "Java format check failed, see 'Run formatter' step for more information."
39+
echo "See https://github.com/google/google-java-format for options on running the formatter locally."
40+
exit 1

.github/workflows/unit.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Java Unit CI
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
37
jobs:
48
build:
59
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ Install `mvn`:
6161

6262
https://maven.apache.org/install.html
6363

64+
### Formatting
65+
This repo follows the Google Java Style guide for formatting. You can setup the
66+
formatting tool locally using one of the options provided at
67+
[google/google-java-format](https://github.com/google/google-java-format#google-java-format).
68+
6469
## Install and Run Invoker Tests Locally
6570

6671
```

functions-framework-api/src/main/java/com/google/cloud/functions/BackgroundFunction.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
/**
1818
* Represents a Cloud Function that is activated by an event and parsed into a user-supplied class.
1919
* The payload of the event is a JSON object, which is deserialized into a user-defined class as
20-
* described for
21-
* <a href="https://github.com/google/gson/blob/master/UserGuide.md#TOC-Object-Examples">Gson</a>.
22-
*
23-
* <p>Here is an example of an implementation that accesses the {@code messageId} property from
24-
* a payload that matches a user-defined {@code PubSubMessage} class:
20+
* described for <a
21+
* href="https://github.com/google/gson/blob/master/UserGuide.md#TOC-Object-Examples">Gson</a>.
2522
*
23+
* <p>Here is an example of an implementation that accesses the {@code messageId} property from a
24+
* payload that matches a user-defined {@code PubSubMessage} class:
2625
* <!-- The {@code} placement is a bit strange here, to prevent spurious spaces introduced by the
2726
* javadoc tool. -->
27+
*
2828
* <pre>
2929
* public class Example implements{@code BackgroundFunction<PubSubMessage>} {
3030
* private static final Logger logger = Logger.getLogger(Example.class.getName());
@@ -49,9 +49,9 @@
4949
@FunctionalInterface
5050
public interface BackgroundFunction<T> {
5151
/**
52-
* Called to service an incoming event. This interface is implemented by user code to
53-
* provide the action for a given background function. If this method throws any exception
54-
* (including any {@link Error}) then the HTTP response will have a 500 status code.
52+
* Called to service an incoming event. This interface is implemented by user code to provide the
53+
* action for a given background function. If this method throws any exception (including any
54+
* {@link Error}) then the HTTP response will have a 500 status code.
5555
*
5656
* @param payload the payload of the event, deserialized from the original JSON string.
5757
* @param context the context of the event. This is a set of values that every event has,

functions-framework-api/src/main/java/com/google/cloud/functions/CloudEventsFunction.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import io.cloudevents.CloudEvent;
44

55
/**
6-
* Represents a Cloud Function that is activated by an event and parsed into a {@link CloudEvent} object.
6+
* Represents a Cloud Function that is activated by an event and parsed into a {@link CloudEvent}
7+
* object.
78
*/
89
@FunctionalInterface
910
public interface CloudEventsFunction {
1011
/**
11-
* Called to service an incoming event. This interface is implemented by user code to
12-
* provide the action for a given background function. If this method throws any exception
13-
* (including any {@link Error}) then the HTTP response will have a 500 status code.
12+
* Called to service an incoming event. This interface is implemented by user code to provide the
13+
* action for a given background function. If this method throws any exception (including any
14+
* {@link Error}) then the HTTP response will have a 500 status code.
1415
*
1516
* @param event the event.
1617
* @throws Exception to produce a 500 status code in the HTTP response.

functions-framework-api/src/main/java/com/google/cloud/functions/Context.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,44 @@
2121
public interface Context {
2222
/**
2323
* Returns event ID.
24-
*
24+
*
2525
* @return event ID
2626
*/
2727
String eventId();
2828

2929
/**
3030
* Returns event timestamp.
31-
*
31+
*
3232
* @return event timestamp
3333
*/
3434
String timestamp();
3535

3636
/**
3737
* Returns event type.
38-
*
38+
*
3939
* @return event type
4040
*/
4141
String eventType();
4242

4343
/**
4444
* Returns event resource.
45-
*
45+
*
4646
* @return event resource
4747
*/
4848
String resource();
4949

5050
/**
5151
* Returns additional attributes from this event. For CloudEvents, the entries in this map will
52-
* include the
53-
* <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">required
54-
* attributes</a> and may include
55-
* <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">optional
56-
* attributes</a> and
57-
* <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes">
52+
* include the <a
53+
* href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">required
54+
* attributes</a> and may include <a
55+
* href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">optional
56+
* attributes</a> and <a
57+
* href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes">
5858
* extension attributes</a>.
5959
*
60-
* <p>The map returned by this method may be empty but is never null.</p>
61-
*
60+
* <p>The map returned by this method may be empty but is never null.
61+
*
6262
* @return additional attributes form this event.
6363
*/
6464
default Map<String, String> attributes() {

functions-framework-api/src/main/java/com/google/cloud/functions/HttpFunction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
package com.google.cloud.functions;
1616

17-
/**
18-
* Represents a Cloud Function that is activated by an HTTP request.
19-
*/
17+
/** Represents a Cloud Function that is activated by an HTTP request. */
2018
@FunctionalInterface
2119
public interface HttpFunction {
2220
/**

functions-framework-api/src/main/java/com/google/cloud/functions/HttpMessage.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import java.util.Map;
2222
import java.util.Optional;
2323

24-
/**
25-
* Represents an HTTP message, either an HTTP request or a part of a multipart HTTP request.
26-
*/
24+
/** Represents an HTTP message, either an HTTP request or a part of a multipart HTTP request. */
2725
public interface HttpMessage {
2826
/**
2927
* Returns the value of the {@code Content-Type} header, if any.
@@ -40,19 +38,19 @@ public interface HttpMessage {
4038
long getContentLength();
4139

4240
/**
43-
* Returns the character encoding specified in the {@code Content-Type} header,
44-
* or {@code Optional.empty()} if there is no {@code Content-Type} header or it does not have the
45-
* {@code charset} parameter.
41+
* Returns the character encoding specified in the {@code Content-Type} header, or {@code
42+
* Optional.empty()} if there is no {@code Content-Type} header or it does not have the {@code
43+
* charset} parameter.
4644
*
4745
* @return the character encoding for the content type, if one is specified.
4846
*/
4947
Optional<String> getCharacterEncoding();
5048

5149
/**
52-
* Returns an {@link InputStream} that can be used to read the body of this HTTP request.
53-
* Every call to this method on the same {@link HttpMessage} will return the same object.
54-
* This method is typically used to read binary data. If the body is text, the
55-
* {@link #getReader()} method is more appropriate.
50+
* Returns an {@link InputStream} that can be used to read the body of this HTTP request. Every
51+
* call to this method on the same {@link HttpMessage} will return the same object. This method is
52+
* typically used to read binary data. If the body is text, the {@link #getReader()} method is
53+
* more appropriate.
5654
*
5755
* @return an {@link InputStream} that can be used to read the body of this HTTP request.
5856
* @throws IOException if a valid {@link InputStream} cannot be returned for some reason.
@@ -72,8 +70,8 @@ public interface HttpMessage {
7270
BufferedReader getReader() throws IOException;
7371

7472
/**
75-
* Returns a map describing the headers of this HTTP request, or this part of a multipart
76-
* request. If the headers look like this...
73+
* Returns a map describing the headers of this HTTP request, or this part of a multipart request.
74+
* If the headers look like this...
7775
*
7876
* <pre>
7977
* Content-Type: text/plain
@@ -82,11 +80,11 @@ public interface HttpMessage {
8280
* </pre>
8381
*
8482
* ...then the returned value will map {@code "Content-Type"} to a one-element list containing
85-
* {@code "text/plain"}, and {@code "Some-Header"} to a two-element list containing
86-
* {@code "some value"} and {@code "another value"}.
83+
* {@code "text/plain"}, and {@code "Some-Header"} to a two-element list containing {@code "some
84+
* value"} and {@code "another value"}.
8785
*
88-
* @return a map where each key is an HTTP header and the corresponding {@code List} value has
89-
* one element for each occurrence of that header.
86+
* @return a map where each key is an HTTP header and the corresponding {@code List} value has one
87+
* element for each occurrence of that header.
9088
*/
9189
Map<String, List<String>> getHeaders();
9290

@@ -104,7 +102,6 @@ public interface HttpMessage {
104102
* and {@code getFirstHeader("Another-Header")} will return {@code Optional.empty()}.
105103
*
106104
* @param name an HTTP header name.
107-
*
108105
* @return the first value of the given header, if present.
109106
*/
110107
default Optional<String> getFirstHeader(String name) {

functions-framework-api/src/main/java/com/google/cloud/functions/HttpRequest.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import java.util.Map;
1919
import java.util.Optional;
2020

21-
/**
22-
* Represents the contents of an HTTP request that is being serviced by a Cloud Function.
23-
*/
21+
/** Represents the contents of an HTTP request that is being serviced by a Cloud Function. */
2422
public interface HttpRequest extends HttpMessage {
2523
/**
2624
* The HTTP method of this request, such as {@code "POST"} or {@code "GET"}.
@@ -37,39 +35,39 @@ public interface HttpRequest extends HttpMessage {
3735
String getUri();
3836

3937
/**
40-
* The path part of the URI for this request, without any query. If the full URI is
41-
* {@code http://foo.com/bar/baz?this=that}, then this method will return {@code /bar/baz}.
38+
* The path part of the URI for this request, without any query. If the full URI is {@code
39+
* http://foo.com/bar/baz?this=that}, then this method will return {@code /bar/baz}.
4240
*
4341
* @return the path part of the URI for this request.
4442
*/
4543
String getPath();
4644

4745
/**
48-
* The query part of the URI for this request. If the full URI is
49-
* {@code http://foo.com/bar/baz?this=that}, then this method will return {@code this=that}.
50-
* If there is no query part, the returned {@code Optional} is empty.
46+
* The query part of the URI for this request. If the full URI is {@code
47+
* http://foo.com/bar/baz?this=that}, then this method will return {@code this=that}. If there is
48+
* no query part, the returned {@code Optional} is empty.
5149
*
5250
* @return the query part of the URI, if any.
5351
*/
5452
Optional<String> getQuery();
5553

5654
/**
57-
* The query parameters of this request. If the full URI is
58-
* {@code http://foo.com/bar?thing=thing1&thing=thing2&cat=hat}, then the returned map will map
59-
* {@code thing} to the list {@code ["thing1", "thing2"]} and {@code cat} to the list with the
60-
* single element {@code "hat"}.
55+
* The query parameters of this request. If the full URI is {@code
56+
* http://foo.com/bar?thing=thing1&thing=thing2&cat=hat}, then the returned map will map {@code
57+
* thing} to the list {@code ["thing1", "thing2"]} and {@code cat} to the list with the single
58+
* element {@code "hat"}.
6159
*
62-
* @return a map where each key is the name of a query parameter and the corresponding
63-
* {@code List} value indicates every value that was associated with that name.
60+
* @return a map where each key is the name of a query parameter and the corresponding {@code
61+
* List} value indicates every value that was associated with that name.
6462
*/
6563
Map<String, List<String>> getQueryParameters();
6664

6765
/**
68-
* The first query parameter with the given name, if any. If the full URI is
69-
* {@code http://foo.com/bar?thing=thing1&thing=thing2&cat=hat}, then
70-
* {@code getFirstQueryParameter("thing")} will return {@code Optional.of("thing1")} and
71-
* {@code getFirstQueryParameter("something")} will return {@code Optional.empty()}. This is a
72-
* more convenient alternative to {@link #getQueryParameters}.
66+
* The first query parameter with the given name, if any. If the full URI is {@code
67+
* http://foo.com/bar?thing=thing1&thing=thing2&cat=hat}, then {@code
68+
* getFirstQueryParameter("thing")} will return {@code Optional.of("thing1")} and {@code
69+
* getFirstQueryParameter("something")} will return {@code Optional.empty()}. This is a more
70+
* convenient alternative to {@link #getQueryParameters}.
7371
*
7472
* @param name a query parameter name.
7573
* @return the first query parameter value with the given name, if any.
@@ -102,8 +100,8 @@ interface HttpPart extends HttpMessage {
102100
* value.
103101
*
104102
* @return a map from part names to part contents.
105-
* @throws IllegalStateException if the {@link #getContentType() content type} is not
106-
* {@code multipart/form-data}.
103+
* @throws IllegalStateException if the {@link #getContentType() content type} is not {@code
104+
* multipart/form-data}.
107105
*/
108106
Map<String, HttpPart> getParts();
109107
}

0 commit comments

Comments
 (0)