├── .gitignore ├── LICENSE ├── README.adoc ├── build.gradle ├── docker-compose.yml ├── gradle.properties ├── gradle ├── pipeline.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── manifest.yml ├── sc-pipelines-pws.yml ├── sc-pipelines.yml ├── sc-pipelines ├── manifest-eureka.yml └── manifest-stubrunner.yml ├── settings.gradle └── src ├── main ├── java │ └── org │ │ └── springframework │ │ └── github │ │ ├── AnalyticsApplication.java │ │ ├── GithubData.java │ │ ├── GithubDataListener.java │ │ ├── GithubDatum.java │ │ ├── InstanceInfoContributor.java │ │ ├── IssueDto.java │ │ ├── Issues.java │ │ ├── IssuesController.java │ │ ├── IssuesRepository.java │ │ └── IssuesService.java └── resources │ ├── application-cloud.yaml │ ├── application-standalone.yaml │ ├── application.yml │ ├── db │ ├── done │ │ └── V2__breaking_change.sql │ └── migration │ │ └── V1__init.sql │ └── json │ └── issue-created.json └── test ├── java ├── e2e │ └── E2eTests.java ├── org │ └── springframework │ │ └── github │ │ ├── AnalyticsApplicationTests.java │ │ └── BaseClass.java └── smoke │ └── IntegrationTests.java └── resources └── contracts └── rest ├── shouldCountIssues.groovy ├── shouldCreateNewIssue.groovy ├── shouldDeleteAllIssues.groovy └── shouldReturnAllIssues.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | /application.yml 2 | /application.properties 3 | asciidoctor.css 4 | *~ 5 | .#* 6 | *# 7 | target/ 8 | build/ 9 | bin/ 10 | _site/ 11 | .classpath 12 | .project 13 | .settings 14 | .springBeans 15 | .DS_Store 16 | *.sw* 17 | *.iml 18 | *.ipr 19 | *.iws 20 | .idea/* 21 | .factorypath 22 | dump.rdb 23 | .apt_generated 24 | artifacts 25 | *.versionsBackup 26 | .gradle 27 | *.log 28 | out -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | https://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | https://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | # github-analytics is no longer actively maintained by VMware, Inc. 2 | 3 | = GitHub Analytics 4 | 5 | GitHub Analytics app. Analyses GitHub messages received from Github Webhook app. Part of the deployment pipeline example. 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'org.springframework.boot' 3 | apply plugin: 'spring-cloud-contract' 4 | apply plugin: 'io.spring.dependency-management' 5 | apply plugin: 'maven-publish' 6 | apply from: 'gradle/pipeline.gradle' 7 | 8 | buildscript { 9 | repositories { 10 | mavenCentral() 11 | mavenLocal() 12 | maven { url "https://repo.spring.io/snapshot" } 13 | maven { url "https://repo.spring.io/milestone" } 14 | maven { url "https://repo.spring.io/release" } 15 | } 16 | dependencies { 17 | classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE" 18 | classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${project.hasProperty("scContractVersion") ? project.property("scContractVersion") : "2.0.0.RELEASE"}" 19 | } 20 | } 21 | 22 | group = 'com.example.github' 23 | version = getProp('newVersion') ?: '0.0.1-SNAPSHOT' 24 | 25 | ext { 26 | projectGroupId = project.group 27 | projectArtifactId = project.name 28 | projectVersion = project.version 29 | // due to CF multiport binding issues we need to hardcode the values 30 | stubrunnerIds = 'com.example.github:github-webhook:+:stubs:10000' 31 | } 32 | 33 | repositories { 34 | mavenCentral() 35 | mavenLocal() 36 | if (getProp("M2_LOCAL")) { 37 | maven { 38 | url getProp("M2_LOCAL") 39 | } 40 | } 41 | maven { url "https://repo.spring.io/snapshot" } 42 | maven { url "https://repo.spring.io/milestone" } 43 | maven { url "https://repo.spring.io/release" } 44 | } 45 | 46 | dependencyManagement { 47 | imports { 48 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:$BOM_VERSION" 49 | } 50 | } 51 | 52 | if (gradle.startParameter.taskRequests.any { it.args.contains("apiCompatibility") }) { 53 | contracts { 54 | baseClassForTests = 'org.springframework.github.BaseClass' 55 | basePackageForTests = 'com.example.contracttests' 56 | contractsPath = "/" 57 | contractsSnapshotCheckSkip = true 58 | contractRepository { 59 | repositoryUrl(getProp('REPO_WITH_JARS') ?: 60 | getProp('REPO_WITH_BINARIES') ?: 'http://localhost:8081/artifactory/libs-release-local') 61 | } 62 | setContractsMode("REMOTE") 63 | contractDependency { 64 | groupId = project.group 65 | artifactId = project.name 66 | delegate.classifier = "stubs" 67 | delegate.version = getProp("latestProductionVersion") 68 | } 69 | } 70 | } else { 71 | contracts { 72 | baseClassForTests = 'org.springframework.github.BaseClass' 73 | basePackageForTests = 'com.example.contracttests' 74 | contractsSnapshotCheckSkip = true 75 | } 76 | } 77 | 78 | dependencies { 79 | compile('org.springframework.analytics:spring-analytics:1.0.0.RELEASE') 80 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 81 | compile('org.hibernate:hibernate-validator:6.0.9.Final') 82 | compile('org.springframework.cloud:spring-cloud-starter-stream-rabbit') 83 | compile('org.springframework.boot:spring-boot-starter-actuator') 84 | compile('org.flywaydb:flyway-core') 85 | compile('org.springframework.boot:spring-boot-starter-data-jpa') 86 | compile('org.springframework.boot:spring-boot-starter-web') 87 | compile('com.h2database:h2') 88 | compile('mysql:mysql-connector-java') 89 | compile('io.micrometer:micrometer-registry-prometheus:1.0.3') 90 | compile('org.springframework.boot:spring-boot-starter-cloud-connectors') 91 | 92 | testCompile('org.springframework.cloud:spring-cloud-starter-contract-stub-runner') 93 | testCompile('org.springframework.cloud:spring-cloud-stream-test-support') 94 | testCompile('org.springframework.cloud:spring-cloud-starter-contract-verifier') 95 | testCompile('org.awaitility:awaitility:3.1.0') 96 | } 97 | 98 | publishing { 99 | repositories { 100 | maven { 101 | url getProp('REPO_WITH_BINARIES_FOR_UPLOAD') ?: 102 | getProp('REPO_WITH_BINARIES') ?: 'http://localhost:8081/artifactory/libs-release-local' 103 | credentials { 104 | username getProp('M2_SETTINGS_REPO_USERNAME') ?: 'admin' 105 | password getProp('M2_SETTINGS_REPO_PASSWORD') ?: 'password' 106 | } 107 | } 108 | } 109 | publications { 110 | mavenJava(MavenPublication) { 111 | artifactId project.name 112 | from components.java 113 | } 114 | } 115 | } 116 | 117 | task wrapper(type: Wrapper) { 118 | gradleVersion = '4.7' 119 | } 120 | 121 | String getProp(String propName) { 122 | return hasProperty(propName) ? 123 | (getProperty(propName) ?: System.properties[propName]) : System.properties[propName] ?: 124 | System.getenv(propName) 125 | } 126 | 127 | 128 | // Fail if no tests are executed 129 | allprojects { 130 | afterEvaluate { 131 | tasks.withType(Test) { 132 | it.testLogging { 133 | exceptionFormat = 'full' 134 | afterSuite { desc, result -> 135 | if (!desc.parent) { 136 | println "Results: (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" 137 | if (result.testCount == 0) { 138 | throw new IllegalStateException("No tests were found. Failing the build") 139 | } 140 | } 141 | } 142 | } 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | mysql: 2 | image: mysql 3 | ports: 4 | - "3306:3306" 5 | environment: 6 | - MYSQL_ROOT_PASSWORD=root 7 | - MYSQL_DATABASE=test 8 | rabbitmq: 9 | image: rabbitmq:management 10 | ports: 11 | - "5672:5672" 12 | - "15672:15672" 13 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.daemon=false 2 | BOM_VERSION=Finchley.RELEASE -------------------------------------------------------------------------------- /gradle/pipeline.gradle: -------------------------------------------------------------------------------- 1 | // TODO: Consider moving these to a plugin: 2 | 3 | test { 4 | description = "Task to run unit and integration tests" 5 | testLogging { 6 | exceptionFormat = 'full' 7 | } 8 | jvmArgs = systemPropsFromGradle() 9 | exclude 'smoke/**' 10 | exclude 'e2e/**' 11 | } 12 | 13 | task smoke(type: Test) { 14 | description = "Task to run smoke tests" 15 | testLogging { 16 | exceptionFormat = 'full' 17 | } 18 | jvmArgs = systemPropsFromGradle() 19 | include 'smoke/**' 20 | } 21 | 22 | task apiCompatibility(type: Test) { 23 | description = "Task to run api compatbility tests" 24 | testLogging { 25 | exceptionFormat = 'full' 26 | } 27 | jvmArgs = systemPropsFromGradle() 28 | include '**/contracttests/**' 29 | } 30 | 31 | task e2e(type: Test) { 32 | description = "Task to run end to end tests" 33 | testLogging { 34 | exceptionFormat = 'full' 35 | } 36 | jvmArgs = systemPropsFromGradle() 37 | include 'e2e/**' 38 | } 39 | 40 | task deploy(dependsOn: 'publish') { 41 | description = "Abstraction over publishing artifacts to Artifactory / Nexus" 42 | } 43 | 44 | task groupId { 45 | doLast { 46 | println projectGroupId 47 | } 48 | } 49 | groupId.description = "Task to retrieve Group ID" 50 | 51 | task artifactId { 52 | doLast { 53 | println projectArtifactId 54 | } 55 | } 56 | artifactId.description = "Task to retrieve Artifact ID" 57 | 58 | task currentVersion { 59 | doLast { 60 | println projectVersion 61 | } 62 | } 63 | currentVersion.description = "Task to retrieve version" 64 | 65 | task stubIds { 66 | doLast { 67 | println stubrunnerIds 68 | } 69 | } 70 | stubIds.description = "Task to retrieve Stub Runner IDS" 71 | 72 | [test, apiCompatibility, smoke, e2e, deploy, groupId, artifactId, currentVersion, stubIds].each { 73 | it.group = "Pipeline" 74 | } 75 | 76 | private List systemPropsFromGradle() { 77 | return project.gradle.startParameter.systemPropertiesArgs.entrySet().collect { "-D${it.key}=${it.value}" } 78 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/github-analytics/0b44c74d96c8e9fbf7c2a548fa90e5ca16951e56/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: github-analytics 4 | services: 5 | - github-rabbitmq 6 | - mysql-github-analytics 7 | - github-eureka 8 | env: 9 | SPRING_PROFILES_ACTIVE: cloud 10 | DEBUG: "true" -------------------------------------------------------------------------------- /sc-pipelines-pws.yml: -------------------------------------------------------------------------------- 1 | # This file describes which services are required by this application 2 | # in order for the smoke tests on the TEST environment and end to end tests 3 | # on the STAGE environment to pass 4 | 5 | # lowercase name of the environment 6 | test: 7 | # list of required services 8 | services: 9 | # type and name of the service 10 | - name: mysql-github-analytics 11 | type: broker 12 | broker: cleardb 13 | plan: spark 14 | - name: github-rabbitmq 15 | type: broker 16 | broker: cloudamqp 17 | plan: lemur 18 | - name: github-eureka 19 | type: app 20 | coordinates: com.example.eureka:github-eureka:0.0.1.M1 21 | pathToManifest: sc-pipelines/manifest-eureka.yml 22 | - name: stubrunner 23 | type: stubrunner 24 | coordinates: com.example.github:github-analytics-stub-runner-boot-classpath-stubs:0.0.1.M1 25 | pathToManifest: sc-pipelines/manifest-stubrunner.yml 26 | stage: 27 | services: 28 | # type and name of the service 29 | - name: mysql-github-analytics 30 | type: broker 31 | broker: cleardb 32 | plan: spark 33 | - name: github-rabbitmq 34 | type: broker 35 | broker: cloudamqp 36 | plan: lemur 37 | - name: github-eureka 38 | type: app 39 | coordinates: com.example.eureka:github-eureka:0.0.1.M1 40 | pathToManifest: sc-pipelines/manifest-eureka.yml 41 | -------------------------------------------------------------------------------- /sc-pipelines.yml: -------------------------------------------------------------------------------- 1 | # This file describes which services are required by this application 2 | # in order for the smoke tests on the TEST environment and end to end tests 3 | # on the STAGE environment to pass 4 | 5 | # lowercase name of the environment 6 | test: 7 | # list of required services 8 | services: 9 | # Prepared for PCF DEV 10 | # type and name of the service 11 | - name: mysql-github-analytics 12 | type: broker 13 | broker: p-mysql 14 | plan: 512mb 15 | - name: github-rabbitmq 16 | type: broker 17 | broker: cloudamqp 18 | plan: lemur 19 | - name: github-eureka 20 | type: app 21 | coordinates: com.example.eureka:github-eureka:0.0.1.M1 22 | pathToManifest: sc-pipelines/manifest-eureka.yml 23 | - type: stubrunner 24 | name: stubrunner 25 | coordinates: com.example.github:github-analytics-stub-runner-boot-classpath-stubs:0.0.1.M1 26 | pathToManifest: sc-pipelines/manifest-stubrunner.yml 27 | stage: 28 | services: 29 | # Prepared for PCF DEV 30 | # type and name of the service 31 | - name: mysql-github-analytics 32 | type: broker 33 | broker: p-mysql 34 | plan: 512mb 35 | - name: github-rabbitmq 36 | type: broker 37 | broker: cloudamqp 38 | plan: lemur 39 | - name: github-eureka 40 | type: app 41 | coordinates: com.example.eureka:github-eureka:0.0.1.M1 42 | pathToManifest: sc-pipelines/manifest-eureka.yml 43 | -------------------------------------------------------------------------------- /sc-pipelines/manifest-eureka.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: github-eureka 4 | services: 5 | - github-rabbitmq 6 | env: 7 | SPRING_PROFILES_ACTIVE: cloud 8 | DEBUG: "true" 9 | # TODO: Remove this from github eureka codebases 10 | APPLICATION_DOMAIN: github-eureka-sc-pipelines-test.cfapps.io 11 | -------------------------------------------------------------------------------- /sc-pipelines/manifest-stubrunner.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: stubrunner 4 | services: 5 | - github-rabbitmq 6 | - github-eureka 7 | env: 8 | SPRING_PROFILES_ACTIVE: cloud 9 | DEBUG: "true" 10 | # TODO: Remove this from github eureka codebases 11 | APPLICATION_DOMAIN: stubrunner-sc-pipelines-test.cfapps.io 12 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'github-analytics' 2 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/AnalyticsApplication.java: -------------------------------------------------------------------------------- 1 | package org.springframework.github; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.java.ServiceScan; 6 | import org.springframework.cloud.stream.annotation.EnableBinding; 7 | import org.springframework.cloud.stream.messaging.Sink; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Profile; 10 | 11 | @SpringBootApplication 12 | @EnableBinding(Sink.class) 13 | public class AnalyticsApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(AnalyticsApplication.class, args); 17 | } 18 | 19 | @Configuration 20 | @ServiceScan 21 | @Profile("cloud") 22 | public class ServiceConfiguration { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/GithubData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.github; 17 | 18 | import java.util.List; 19 | 20 | public class GithubData { 21 | 22 | private List data; 23 | 24 | public List getData() { 25 | return data; 26 | } 27 | 28 | public void setData(List data) { 29 | this.data = data; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/GithubDataListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.github; 17 | 18 | import java.lang.invoke.MethodHandles; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | import org.springframework.cloud.stream.annotation.StreamListener; 23 | import org.springframework.cloud.stream.messaging.Sink; 24 | import org.springframework.stereotype.Component; 25 | 26 | @Component 27 | class GithubDataListener { 28 | 29 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 30 | 31 | private final IssuesService service; 32 | 33 | GithubDataListener(IssuesService service) { 34 | this.service = service; 35 | } 36 | 37 | @StreamListener(Sink.INPUT) 38 | public void listen(GithubDatum data) { 39 | log.info("Received a new message [{}]", data); 40 | service.save(data.getUsername(), data.getRepository()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/GithubDatum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.github; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | public class GithubDatum { 22 | 23 | private String username; 24 | 25 | private String repository; 26 | 27 | private String type = "unknown"; 28 | 29 | private String action = "unknown"; 30 | 31 | public GithubDatum(String username, String repository, String type, String action) { 32 | this.username = username; 33 | this.repository = repository; 34 | this.type = type; 35 | this.action = action; 36 | } 37 | 38 | public GithubDatum() { 39 | } 40 | 41 | public String getUsername() { 42 | return this.username; 43 | } 44 | 45 | public void setUsername(String username) { 46 | this.username = username; 47 | } 48 | 49 | public String getRepository() { 50 | return this.repository; 51 | } 52 | 53 | public void setRepository(String repository) { 54 | this.repository = repository; 55 | } 56 | 57 | public String getType() { 58 | return this.type; 59 | } 60 | 61 | public void setType(String type) { 62 | this.type = type; 63 | } 64 | 65 | public String getAction() { 66 | return this.action; 67 | } 68 | 69 | public void setAction(String action) { 70 | this.action = action; 71 | } 72 | 73 | @Override public String toString() { 74 | return "GithubDatum{" + "username='" + username + '\'' + ", repository='" 75 | + repository + '\'' + ", type='" + type + '\'' + ", action='" + action 76 | + '\'' + '}'; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/InstanceInfoContributor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.github; 2 | 3 | import java.util.Collections; 4 | 5 | import org.springframework.boot.actuate.info.Info; 6 | import org.springframework.boot.actuate.info.InfoContributor; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | class InstanceInfoContributor implements InfoContributor { 11 | 12 | @Override 13 | public void contribute(Info.Builder builder) { 14 | builder.withDetail("cf_instance", 15 | Collections.singletonMap("id", System.getenv("INSTANCE_GUID"))); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/IssueDto.java: -------------------------------------------------------------------------------- 1 | package org.springframework.github; 2 | 3 | class IssueDto { 4 | private String userName; 5 | private String repository; 6 | 7 | IssueDto(String userName, String repository) { 8 | this.userName = userName; 9 | this.repository = repository; 10 | } 11 | 12 | IssueDto() { 13 | } 14 | 15 | public String getUserName() { 16 | return userName; 17 | } 18 | 19 | public void setUserName(String userName) { 20 | this.userName = userName; 21 | } 22 | 23 | public String getRepository() { 24 | return repository; 25 | } 26 | 27 | public void setRepository(String repository) { 28 | this.repository = repository; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/Issues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.github; 18 | 19 | import javax.persistence.Entity; 20 | import javax.persistence.GeneratedValue; 21 | import javax.persistence.GenerationType; 22 | import javax.persistence.Id; 23 | import javax.persistence.Table; 24 | import javax.validation.constraints.NotNull; 25 | 26 | @Entity 27 | @Table(name = "issues") 28 | class Issues { 29 | @Id 30 | @GeneratedValue(strategy = GenerationType.IDENTITY) 31 | private Long id; 32 | @NotNull 33 | private String username; 34 | @NotNull 35 | private String repository; 36 | 37 | Issues(String username, String repository) { 38 | this.username = username; 39 | this.repository = repository; 40 | } 41 | 42 | Issues() { 43 | } 44 | 45 | String getUsername() { 46 | return this.username; 47 | } 48 | 49 | void setUsername(String username) { 50 | this.username = username; 51 | } 52 | 53 | String getRepository() { 54 | return this.repository; 55 | } 56 | 57 | void setRepository(String lastname) { 58 | this.repository = lastname; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "IssueCreation [username=" + this.username + ", repository=" + this.repository 64 | + "]"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/IssuesController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.github; 17 | 18 | import java.lang.invoke.MethodHandles; 19 | import java.time.LocalDateTime; 20 | import java.util.List; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.util.Assert; 25 | import org.springframework.web.bind.annotation.DeleteMapping; 26 | import org.springframework.web.bind.annotation.GetMapping; 27 | import org.springframework.web.bind.annotation.PostMapping; 28 | import org.springframework.web.bind.annotation.RequestBody; 29 | import org.springframework.web.bind.annotation.RequestMapping; 30 | import org.springframework.web.bind.annotation.RestController; 31 | 32 | @RestController 33 | @RequestMapping("/issues") 34 | class IssuesController { 35 | 36 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 37 | 38 | private final IssuesService service; 39 | 40 | IssuesController(IssuesService service) { 41 | this.service = service; 42 | } 43 | 44 | @GetMapping("/count") 45 | public long count() { 46 | long size = service.numberOfIssues(); 47 | log.info("Size of issues equals [{}]", size); 48 | return size; 49 | } 50 | 51 | @GetMapping 52 | public List allIssues() { 53 | return service.allIssues(); 54 | } 55 | 56 | @PostMapping 57 | public void save(@RequestBody IssueDto issue) { 58 | if (issue == null) { 59 | data(); 60 | return; 61 | } 62 | Assert.hasText(issue.getUserName(), "username must be set"); 63 | Assert.hasText(issue.getRepository(), "repository must be set"); 64 | service.save(issue.getUserName(), issue.getRepository()); 65 | } 66 | 67 | private void data() { 68 | String time = LocalDateTime.now().toString(); 69 | String repo = "spring-cloud/" + time; 70 | log.info("Will store an issue name [{}], repo [{}]", time, repo); 71 | service.save(time, repo); 72 | } 73 | 74 | @DeleteMapping 75 | public void delete() { 76 | service.deleteAll(); 77 | } 78 | 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/IssuesRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.github; 18 | 19 | import org.springframework.data.repository.CrudRepository; 20 | import org.springframework.stereotype.Repository; 21 | 22 | @Repository 23 | interface IssuesRepository extends CrudRepository { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/github/IssuesService.java: -------------------------------------------------------------------------------- 1 | package org.springframework.github; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import io.micrometer.core.instrument.MeterRegistry; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @author Marcin Grzejszczak 13 | */ 14 | @Service 15 | class IssuesService { 16 | private static final Logger log = LoggerFactory.getLogger(IssuesService.class); 17 | 18 | private final IssuesRepository repository; 19 | 20 | IssuesService(IssuesRepository repository, MeterRegistry meterRegistry) { 21 | this.repository = repository; 22 | meterRegistry.gauge("issues", this, IssuesService::count); 23 | } 24 | 25 | void save(String user, String repo) { 26 | log.info("Saving user [{}], and repo [{}]", user, repo); 27 | this.repository.save(new Issues(user, repo)); 28 | } 29 | 30 | List allIssues() { 31 | List dtos = new ArrayList<>(); 32 | this.repository.findAll().forEach(i -> dtos.add(new IssueDto(i.getUsername(), i.getRepository()))); 33 | return dtos; 34 | } 35 | 36 | long numberOfIssues() { 37 | return count(); 38 | } 39 | 40 | private long count() { 41 | return this.repository.count(); 42 | } 43 | 44 | void deleteAll() { 45 | log.info("Deleting all issues"); 46 | this.repository.deleteAll(); 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/application-cloud.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq.addresses: ${vcap.services.github-rabbitmq.credentials.uri} 3 | jpa.hibernate.ddl-auto: none 4 | datasource: 5 | driverClassName: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://192.168.99.100/github?autoReconnect=true&useSSL=false 7 | username: root 8 | password: test -------------------------------------------------------------------------------- /src/main/resources/application-standalone.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq.host: 192.168.99.100 3 | jpa.hibernate.ddl-auto: none 4 | datasource: 5 | driverClassName: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://192.168.99.100:3306/test?autoReconnect=true&useSSL=false 7 | username: root 8 | password: root -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application.name: github-analytics 3 | 4 | cloud.stream.bindings.input: 5 | destination: messages 6 | group: github-analytics 7 | 8 | jpa: 9 | database: MYSQL 10 | 11 | server.port: ${PORT:8081} 12 | 13 | management.endpoints.web.exposure.include: "*" 14 | management.endpoints.web.base-path: / 15 | -------------------------------------------------------------------------------- /src/main/resources/db/done/V2__breaking_change.sql: -------------------------------------------------------------------------------- 1 | -- This change is backward incompatible - you can't do A/B testing 2 | ALTER TABLE issues CHANGE repository repo VARCHAR(255); -------------------------------------------------------------------------------- /src/main/resources/db/migration/V1__init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE issues ( 2 | id BIGINT PRIMARY KEY AUTO_INCREMENT, 3 | username varchar(255) not null, 4 | repository varchar(255) not null 5 | ); -------------------------------------------------------------------------------- /src/main/resources/json/issue-created.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "created", 3 | "issue": { 4 | "url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/559", 5 | "repository_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix", 6 | "labels_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/559/labels{/name}", 7 | "comments_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/559/comments", 8 | "events_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/559/events", 9 | "html_url": "https://github.com/spring-cloud/spring-cloud-netflix/issues/559", 10 | "id": 108688072, 11 | "number": 559, 12 | "title": "DiscoveryClient content seems null", 13 | "user": { 14 | "login": "elerion", 15 | "id": 14874472, 16 | "avatar_url": "https://avatars.githubusercontent.com/u/14874472?v=3", 17 | "gravatar_id": "", 18 | "url": "https://api.github.com/users/elerion", 19 | "html_url": "https://github.com/elerion", 20 | "followers_url": "https://api.github.com/users/elerion/followers", 21 | "following_url": "https://api.github.com/users/elerion/following{/other_user}", 22 | "gists_url": "https://api.github.com/users/elerion/gists{/gist_id}", 23 | "starred_url": "https://api.github.com/users/elerion/starred{/owner}{/repo}", 24 | "subscriptions_url": "https://api.github.com/users/elerion/subscriptions", 25 | "organizations_url": "https://api.github.com/users/elerion/orgs", 26 | "repos_url": "https://api.github.com/users/elerion/repos", 27 | "events_url": "https://api.github.com/users/elerion/events{/privacy}", 28 | "received_events_url": "https://api.github.com/users/elerion/received_events", 29 | "type": "User", 30 | "site_admin": false 31 | }, 32 | "labels": [ 33 | { 34 | "url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/labels/question", 35 | "name": "question", 36 | "color": "cc317c" 37 | } 38 | ], 39 | "state": "closed", 40 | "locked": false, 41 | "assignee": null, 42 | "milestone": null, 43 | "comments": 14, 44 | "created_at": "2015-09-28T15:51:07Z", 45 | "updated_at": "2016-04-13T21:46:21Z", 46 | "closed_at": "2015-09-30T10:32:10Z", 47 | "body": "Hi,\r\n\r\nI use SNAPSHOT version add when i try to autowired the discoveryClient the content is null, my service is registered to eurekaServer.\r\n\r\nI haven't this problem with the milestones (M1) version\r\n\r\n```java\r\n@Component\r\npublic class EurekaClients {\r\n\r\n\t@Autowired\r\n\t@Lazy\r\n\tprivate DiscoveryClient discoveryClient;\r\n\r\n\t@Autowired\r\n\tprivate SwaggerConfig swaggerConfig;\r\n\r\n\tpublic HashMap getAllClients() {\r\n\t\tHashMap urlClients = new HashMap();\r\n\t\tdiscoveryClient.getApplications().getRegisteredApplications().forEach(a -> {\r\n\t\t\ta.getInstances().forEach(i -> {\r\n\t\t\t\turlClients.put(i.getAppName(),\r\n\t\t\t\t\t\tswaggerConfig.getPath() + i.getHomePageUrl().toString() + swaggerConfig.getPattern());\r\n\t\t\t});\r\n\t\t});\r\n\t\treturn urlClients;\r\n\t}\r\n\r\n}\r\n```\r\n\r\nI have this exception : \r\n\r\n```\r\norg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.netflix.discovery.DiscoveryClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.context.annotation.Lazy(value=true)}\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver$1.getTarget(ContextAnnotationAutowireCandidateResolver.java:82) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.getTarget(CglibAopProxy.java:685) ~[spring-aop-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:636) ~[spring-aop-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat com.netflix.discovery.DiscoveryClient$$EnhancerBySpringCGLIB$$68978133.getApplications() ~[spring-core-4.2.1.RELEASE.jar:1.2.5]\r\n\tat com.wl.protys.tools.swagger.EurekaClients.getAllClients(EurekaClients.java:28) ~[classes/:na]\r\n\tat com.wl.protys.tools.swagger.IndexController.index(IndexController.java:16) ~[classes/:na]\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]\r\n\tat java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:249) ~[spring-boot-actuator-1.3.0.M5.jar:1.3.0.M5]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102) ~[spring-boot-actuator-1.3.0.M5.jar:1.3.0.M5]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:69) ~[spring-boot-actuator-1.3.0.M5.jar:1.3.0.M5]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) ~[tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_11]\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_11]\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.26.jar:8.0.26]\r\n\tat java.lang.Thread.run(Thread.java:745) [na:1.8.0_11]\r\n```\r\n\r\nAnd this is the content of my discoveryClient variable\r\n![erreureureka](https://cloud.githubusercontent.com/assets/14874472/10140683/0eadc780-6609-11e5-990a-628cfa806e38.PNG)\r\n" 48 | }, 49 | "comment": { 50 | "url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/comments/209662068", 51 | "html_url": "https://github.com/spring-cloud/spring-cloud-netflix/issues/559#issuecomment-209662068", 52 | "issue_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/559", 53 | "id": 209662068, 54 | "user": { 55 | "login": "smithapitla", 56 | "id": 3036820, 57 | "avatar_url": "https://avatars.githubusercontent.com/u/3036820?v=3", 58 | "gravatar_id": "", 59 | "url": "https://api.github.com/users/smithapitla", 60 | "html_url": "https://github.com/smithapitla", 61 | "followers_url": "https://api.github.com/users/smithapitla/followers", 62 | "following_url": "https://api.github.com/users/smithapitla/following{/other_user}", 63 | "gists_url": "https://api.github.com/users/smithapitla/gists{/gist_id}", 64 | "starred_url": "https://api.github.com/users/smithapitla/starred{/owner}{/repo}", 65 | "subscriptions_url": "https://api.github.com/users/smithapitla/subscriptions", 66 | "organizations_url": "https://api.github.com/users/smithapitla/orgs", 67 | "repos_url": "https://api.github.com/users/smithapitla/repos", 68 | "events_url": "https://api.github.com/users/smithapitla/events{/privacy}", 69 | "received_events_url": "https://api.github.com/users/smithapitla/received_events", 70 | "type": "User", 71 | "site_admin": false 72 | }, 73 | "created_at": "2016-04-13T21:46:21Z", 74 | "updated_at": "2016-04-13T21:46:21Z", 75 | "body": "@dsyer \r\nList list = client.getInstances(service) returns empty list even though I see the services as running in eureka. I tried using EurekaClient, DiscoveryClient and EurekaDiscoveryClient. But no luck there :( any idea what could be wrong. " 76 | }, 77 | "repository": { 78 | "id": 21741891, 79 | "name": "spring-cloud-netflix", 80 | "full_name": "spring-cloud/spring-cloud-netflix", 81 | "owner": { 82 | "login": "spring-cloud", 83 | "id": 7815877, 84 | "avatar_url": "https://avatars.githubusercontent.com/u/7815877?v=3", 85 | "gravatar_id": "", 86 | "url": "https://api.github.com/users/spring-cloud", 87 | "html_url": "https://github.com/spring-cloud", 88 | "followers_url": "https://api.github.com/users/spring-cloud/followers", 89 | "following_url": "https://api.github.com/users/spring-cloud/following{/other_user}", 90 | "gists_url": "https://api.github.com/users/spring-cloud/gists{/gist_id}", 91 | "starred_url": "https://api.github.com/users/spring-cloud/starred{/owner}{/repo}", 92 | "subscriptions_url": "https://api.github.com/users/spring-cloud/subscriptions", 93 | "organizations_url": "https://api.github.com/users/spring-cloud/orgs", 94 | "repos_url": "https://api.github.com/users/spring-cloud/repos", 95 | "events_url": "https://api.github.com/users/spring-cloud/events{/privacy}", 96 | "received_events_url": "https://api.github.com/users/spring-cloud/received_events", 97 | "type": "Organization", 98 | "site_admin": false 99 | }, 100 | "private": false, 101 | "html_url": "https://github.com/spring-cloud/spring-cloud-netflix", 102 | "description": "Integration with Netflix OSS components", 103 | "fork": false, 104 | "url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix", 105 | "forks_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/forks", 106 | "keys_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/keys{/key_id}", 107 | "collaborators_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/collaborators{/collaborator}", 108 | "teams_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/teams", 109 | "hooks_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/hooks", 110 | "issue_events_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/events{/number}", 111 | "events_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/events", 112 | "assignees_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/assignees{/user}", 113 | "branches_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/branches{/branch}", 114 | "tags_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/tags", 115 | "blobs_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/git/blobs{/sha}", 116 | "git_tags_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/git/tags{/sha}", 117 | "git_refs_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/git/refs{/sha}", 118 | "trees_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/git/trees{/sha}", 119 | "statuses_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/statuses/{sha}", 120 | "languages_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/languages", 121 | "stargazers_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/stargazers", 122 | "contributors_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/contributors", 123 | "subscribers_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/subscribers", 124 | "subscription_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/subscription", 125 | "commits_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/commits{/sha}", 126 | "git_commits_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/git/commits{/sha}", 127 | "comments_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/comments{/number}", 128 | "issue_comment_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/comments{/number}", 129 | "contents_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/contents/{+path}", 130 | "compare_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/compare/{base}...{head}", 131 | "merges_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/merges", 132 | "archive_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/{archive_format}{/ref}", 133 | "downloads_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/downloads", 134 | "issues_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues{/number}", 135 | "pulls_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/pulls{/number}", 136 | "milestones_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/milestones{/number}", 137 | "notifications_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/notifications{?since,all,participating}", 138 | "labels_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/labels{/name}", 139 | "releases_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/releases{/id}", 140 | "deployments_url": "https://api.github.com/repos/spring-cloud/spring-cloud-netflix/deployments", 141 | "created_at": "2014-07-11T15:46:12Z", 142 | "updated_at": "2016-04-13T16:34:23Z", 143 | "pushed_at": "2016-04-13T04:00:13Z", 144 | "git_url": "git://github.com/spring-cloud/spring-cloud-netflix.git", 145 | "ssh_url": "git@github.com:spring-cloud/spring-cloud-netflix.git", 146 | "clone_url": "https://github.com/spring-cloud/spring-cloud-netflix.git", 147 | "svn_url": "https://github.com/spring-cloud/spring-cloud-netflix", 148 | "homepage": "https://cloud.spring.io/spring-cloud-netflix/", 149 | "size": 6756, 150 | "stargazers_count": 333, 151 | "watchers_count": 333, 152 | "language": "Java", 153 | "has_issues": true, 154 | "has_downloads": true, 155 | "has_wiki": true, 156 | "has_pages": true, 157 | "forks_count": 209, 158 | "mirror_url": null, 159 | "open_issues_count": 136, 160 | "forks": 209, 161 | "open_issues": 136, 162 | "watchers": 333, 163 | "default_branch": "master" 164 | }, 165 | "organization": { 166 | "login": "spring-cloud", 167 | "id": 7815877, 168 | "url": "https://api.github.com/orgs/spring-cloud", 169 | "repos_url": "https://api.github.com/orgs/spring-cloud/repos", 170 | "events_url": "https://api.github.com/orgs/spring-cloud/events", 171 | "hooks_url": "https://api.github.com/orgs/spring-cloud/hooks", 172 | "issues_url": "https://api.github.com/orgs/spring-cloud/issues", 173 | "members_url": "https://api.github.com/orgs/spring-cloud/members{/member}", 174 | "public_members_url": "https://api.github.com/orgs/spring-cloud/public_members{/member}", 175 | "avatar_url": "https://avatars.githubusercontent.com/u/7815877?v=3", 176 | "description": "Tools for building common patterns in distributed systems with Spring" 177 | }, 178 | "sender": { 179 | "login": "smithapitla", 180 | "id": 3036820, 181 | "avatar_url": "https://avatars.githubusercontent.com/u/3036820?v=3", 182 | "gravatar_id": "", 183 | "url": "https://api.github.com/users/smithapitla", 184 | "html_url": "https://github.com/smithapitla", 185 | "followers_url": "https://api.github.com/users/smithapitla/followers", 186 | "following_url": "https://api.github.com/users/smithapitla/following{/other_user}", 187 | "gists_url": "https://api.github.com/users/smithapitla/gists{/gist_id}", 188 | "starred_url": "https://api.github.com/users/smithapitla/starred{/owner}{/repo}", 189 | "subscriptions_url": "https://api.github.com/users/smithapitla/subscriptions", 190 | "organizations_url": "https://api.github.com/users/smithapitla/orgs", 191 | "repos_url": "https://api.github.com/users/smithapitla/repos", 192 | "events_url": "https://api.github.com/users/smithapitla/events{/privacy}", 193 | "received_events_url": "https://api.github.com/users/smithapitla/received_events", 194 | "type": "User", 195 | "site_admin": false 196 | } 197 | } -------------------------------------------------------------------------------- /src/test/java/e2e/E2eTests.java: -------------------------------------------------------------------------------- 1 | package e2e; 2 | 3 | import java.io.IOException; 4 | import java.lang.invoke.MethodHandles; 5 | import java.net.URI; 6 | import java.nio.file.Files; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.apache.commons.logging.Log; 10 | import org.apache.commons.logging.LogFactory; 11 | import org.awaitility.Awaitility; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.springframework.beans.factory.annotation.Value; 15 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 16 | import org.springframework.boot.test.context.SpringBootTest; 17 | import org.springframework.core.io.Resource; 18 | import org.springframework.http.MediaType; 19 | import org.springframework.http.RequestEntity; 20 | import org.springframework.http.ResponseEntity; 21 | import org.springframework.test.context.junit4.SpringRunner; 22 | import org.springframework.web.client.RestTemplate; 23 | 24 | import static org.assertj.core.api.BDDAssertions.then; 25 | import static org.awaitility.Awaitility.await; 26 | 27 | /** 28 | * @author Marcin Grzejszczak 29 | */ 30 | @RunWith(SpringRunner.class) 31 | @SpringBootTest(classes = E2eTests.class, 32 | webEnvironment = SpringBootTest.WebEnvironment.NONE) 33 | @EnableAutoConfiguration 34 | public class E2eTests { 35 | 36 | private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass()); 37 | 38 | @Value("${application.url}") String applicationUrl; 39 | @Value("${classpath:json/issue-created.json}") Resource json; 40 | @Value("${test.timeout:60}") Long timeout; 41 | 42 | RestTemplate restTemplate = new RestTemplate(); 43 | 44 | @Test 45 | public void shouldStoreAMessageWhenGithubDataWasReceivedViaMessaging() 46 | throws IOException { 47 | Awaitility.await().atMost(this.timeout, TimeUnit.SECONDS).untilAsserted(() -> { 48 | final Integer countOfEntries = countGithubData(); 49 | log.info("Initial count is [" + countOfEntries + "]"); 50 | 51 | ResponseEntity response = callData(); 52 | then(response.getStatusCode().is2xxSuccessful()).isTrue(); 53 | then(response.getBody()).isNotNull(); 54 | 55 | log.info("Awaiting proper count of github data"); 56 | await().until(() -> countGithubData() > countOfEntries); 57 | }); 58 | } 59 | 60 | private ResponseEntity callData() throws IOException { 61 | return this.restTemplate.exchange(RequestEntity 62 | .post(URI.create("http://" + 63 | this.applicationUrl.replace("github-analytics", "github-webhook"))) 64 | .contentType(MediaType.APPLICATION_JSON) 65 | .body(data()), String.class); 66 | } 67 | 68 | public String data() throws IOException { 69 | return new String(Files.readAllBytes(this.json.getFile().toPath())); 70 | } 71 | 72 | private Integer countGithubData() { 73 | Integer response = this.restTemplate 74 | .getForObject("http://" + this.applicationUrl + "/issues/count", Integer.class); 75 | log.info("Received response [" + response + "]"); 76 | return response; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/github/AnalyticsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.github; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.cloud.contract.stubrunner.StubTrigger; 8 | import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; 9 | import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; 10 | import org.springframework.test.context.ActiveProfiles; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.assertj.core.api.BDDAssertions.then; 15 | 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @SpringBootTest(classes = AnalyticsApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) 18 | @AutoConfigureStubRunner(ids = {"com.example.github:github-webhook"}, 19 | repositoryRoot = "${REPO_WITH_JARS:https://repo.spring.io/milestone/}", 20 | stubsMode = StubRunnerProperties.StubsMode.REMOTE) 21 | @ActiveProfiles("test") 22 | public class AnalyticsApplicationTests { 23 | 24 | @Autowired StubTrigger stubTrigger; 25 | @Autowired IssuesRepository repo; 26 | 27 | @Test 28 | public void should_store_a_new_issue() { 29 | assertThat(this.repo.count()).isEqualTo(0L); 30 | 31 | this.stubTrigger.trigger("issue_created_v2"); 32 | 33 | then(this.repo.count()).isEqualTo(1L); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/test/java/org/springframework/github/BaseClass.java: -------------------------------------------------------------------------------- 1 | package org.springframework.github; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import io.restassured.module.mockmvc.RestAssuredMockMvc; 7 | import org.junit.Before; 8 | import org.mockito.Mockito; 9 | 10 | import static org.mockito.BDDMockito.given; 11 | 12 | /** 13 | * @author Marcin Grzejszczak 14 | */ 15 | public class BaseClass { 16 | 17 | @Before 18 | public void setup() { 19 | RestAssuredMockMvc.standaloneSetup(new IssuesController(issuesService())); 20 | } 21 | 22 | IssuesService issuesService() { 23 | IssuesService repo = Mockito.mock(IssuesService.class); 24 | given(repo.numberOfIssues()).willReturn(5L); 25 | given(repo.allIssues()).willReturn(issues()); 26 | return repo; 27 | } 28 | 29 | private List issues() { 30 | List dtos = new ArrayList<>(); 31 | dtos.add(new IssueDto("foo", "spring-cloud/bar")); 32 | return dtos; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/smoke/IntegrationTests.java: -------------------------------------------------------------------------------- 1 | package smoke; 2 | 3 | import java.lang.invoke.MethodHandles; 4 | import java.util.Map; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.apache.commons.logging.Log; 8 | import org.apache.commons.logging.LogFactory; 9 | import org.awaitility.Awaitility; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import org.springframework.http.ResponseEntity; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | import org.springframework.web.client.RestTemplate; 18 | 19 | import static org.assertj.core.api.BDDAssertions.then; 20 | import static org.awaitility.Awaitility.await; 21 | 22 | /** 23 | * @author Marcin Grzejszczak 24 | */ 25 | @RunWith(SpringRunner.class) 26 | @SpringBootTest(classes = IntegrationTests.class, 27 | webEnvironment = SpringBootTest.WebEnvironment.NONE) 28 | @EnableAutoConfiguration 29 | public class IntegrationTests { 30 | 31 | private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass()); 32 | 33 | @Value("${stubrunner.url}") String stubRunnerUrl; 34 | @Value("${application.url}") String applicationUrl; 35 | @Value("${test.timeout:60}") Long timeout; 36 | 37 | RestTemplate restTemplate = new RestTemplate(); 38 | 39 | @Test 40 | public void shouldStoreAMessageWhenGithubDataWasReceivedViaMessaging() { 41 | Awaitility.await().atMost(this.timeout, TimeUnit.SECONDS).untilAsserted(() -> { 42 | final Integer countOfEntries = countGithubData(); 43 | log.info("Initial count is [" + countOfEntries + "]"); 44 | 45 | ResponseEntity response = triggerMessage(); 46 | then(response.getStatusCode().is2xxSuccessful()).isTrue(); 47 | log.info("Triggered additional message"); 48 | 49 | log.info("Awaiting proper count of github data"); 50 | await().until(() -> countGithubData() > countOfEntries); 51 | }); 52 | } 53 | 54 | private ResponseEntity triggerMessage() { 55 | return this.restTemplate.postForEntity("http://" + 56 | this.stubRunnerUrl + "/triggers/issue_created_v2", "", Map.class); 57 | } 58 | 59 | private Integer countGithubData() { 60 | Integer response = this.restTemplate 61 | .getForObject("http://" + this.applicationUrl + "/issues/count", Integer.class); 62 | log.info("Received response [" + response + "]"); 63 | return response; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/resources/contracts/rest/shouldCountIssues.groovy: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | org.springframework.cloud.contract.spec.Contract.make { 4 | request { 5 | method GET() 6 | url '/issues/count' 7 | } 8 | response { 9 | status 200 10 | body 5 11 | } 12 | } -------------------------------------------------------------------------------- /src/test/resources/contracts/rest/shouldCreateNewIssue.groovy: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | org.springframework.cloud.contract.spec.Contract.make { 4 | request { 5 | method POST() 6 | url '/issues' 7 | body( 8 | userName: 'foo', 9 | repository: 'spring-cloud/bar' 10 | ) 11 | headers { 12 | contentType(applicationJson()) 13 | } 14 | } 15 | response { 16 | status 200 17 | } 18 | } -------------------------------------------------------------------------------- /src/test/resources/contracts/rest/shouldDeleteAllIssues.groovy: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | org.springframework.cloud.contract.spec.Contract.make { 4 | request { 5 | method DELETE() 6 | url '/issues' 7 | } 8 | response { 9 | status 200 10 | } 11 | } -------------------------------------------------------------------------------- /src/test/resources/contracts/rest/shouldReturnAllIssues.groovy: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | org.springframework.cloud.contract.spec.Contract.make { 4 | request { 5 | method GET() 6 | url '/issues' 7 | } 8 | response { 9 | status 200 10 | body( 11 | userName: 'foo', 12 | repository: 'spring-cloud/bar' 13 | ) 14 | } 15 | } --------------------------------------------------------------------------------