@@ -33,8 +33,8 @@ import kotlinx.coroutines.withContext
33
33
34
34
import org.apache.logging.log4j.kotlin.Logging
35
35
36
- import org.ossreviewtoolkit.advisor.AbstractAdviceProviderFactory
37
36
import org.ossreviewtoolkit.advisor.AdviceProvider
37
+ import org.ossreviewtoolkit.advisor.AdviceProviderFactory
38
38
import org.ossreviewtoolkit.clients.github.DateTime
39
39
import org.ossreviewtoolkit.clients.github.GitHubService
40
40
import org.ossreviewtoolkit.clients.github.Paging
@@ -82,15 +82,34 @@ import org.ossreviewtoolkit.utils.ort.showStackTrace
82
82
*/
83
83
class GitHubDefects (name : String , config : GitHubDefectsConfiguration ) : AdviceProvider(name) {
84
84
companion object : Logging {
85
+ /* *
86
+ * The default list of label to filter that typically indicate that an issue is not a defect.
87
+ */
88
+ val DEFAULT_LABEL_FILTER = listOf (" !duplicate" , " !enhancement" , " !invalid" , " !question" , " *" )
89
+
85
90
/* *
86
91
* The default number of parallel requests executed by this advisor implementation. This value is used if the
87
92
* corresponding property in the configuration is unspecified. It is chosen rather arbitrarily.
88
93
*/
89
94
const val DEFAULT_PARALLEL_REQUESTS = 4
90
95
}
91
96
92
- class Factory : AbstractAdviceProviderFactory <GitHubDefects >(" GitHubDefects" ) {
93
- override fun create (config : AdvisorConfiguration ) = GitHubDefects (type, config.forProvider { gitHubDefects })
97
+ class Factory : AdviceProviderFactory {
98
+ override val type = " GitHubDefects"
99
+
100
+ override fun create (config : AdvisorConfiguration ) =
101
+ GitHubDefects (type, config.gitHubDefects ? : parseSpecificConfig(emptyMap()))
102
+
103
+ override fun parseConfig (config : Map <String , String >) =
104
+ AdvisorConfiguration (gitHubDefects = parseSpecificConfig(config))
105
+
106
+ private fun parseSpecificConfig (config : Map <String , String >) = GitHubDefectsConfiguration (
107
+ token = config[" token" ].orEmpty(),
108
+ endpointUrl = config[" endpointUrl" ] ? : GitHubService .ENDPOINT ,
109
+ labelFilter = config[" labelFilter" ]?.split(' ,' )?.map { it.trim() } ? : DEFAULT_LABEL_FILTER ,
110
+ maxNumberOfIssuesPerRepository = config[" maxNumberOfIssuesPerRepository" ]?.toIntOrNull() ? : Int .MAX_VALUE ,
111
+ parallelRequests = config[" parallelRequests" ]?.toIntOrNull() ? : DEFAULT_PARALLEL_REQUESTS ,
112
+ )
94
113
}
95
114
96
115
/* *
@@ -103,16 +122,16 @@ class GitHubDefects(name: String, config: GitHubDefectsConfiguration) : AdvicePr
103
122
private val labelFilters = config.labelFilter.toLabelFilters()
104
123
105
124
/* * The maximum number of defects to retrieve. */
106
- private val maxDefects = config.maxNumberOfIssuesPerRepository ? : Int . MAX_VALUE
125
+ private val maxDefects = config.maxNumberOfIssuesPerRepository
107
126
108
127
/* * The number of requests to be processed in parallel. */
109
- private val parallelRequests = config.parallelRequests ? : DEFAULT_PARALLEL_REQUESTS
128
+ private val parallelRequests = config.parallelRequests
110
129
111
130
/* * The service for accessing the GitHub GraphQL API. */
112
131
private val service by lazy {
113
132
GitHubService .create(
114
- token = config.token.orEmpty() ,
115
- url = config.endpointUrl ? : GitHubService . ENDPOINT ,
133
+ token = config.token,
134
+ url = config.endpointUrl,
116
135
client = HttpClient (OkHttp )
117
136
)
118
137
}
0 commit comments