Skip to content

Commit fa4f8d2

Browse files
committed
◀️ automate 404 scenario
1 parent b2e784d commit fa4f8d2

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

Diff for: .idea/awesome-android-kotlin-apps.iml

-2
This file was deleted.

Diff for: .idea/codeStyles/Project.xml

+1-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/compiler.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/kotlinc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/main/kotlin/com/github/aaka/App.kt

+15-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.github.aaka.di.DaggerAppComponent
1010
import com.github.aaka.utils.DateTimeUtils
1111
import kotlinx.coroutines.runBlocking
1212
import retrofit2.HttpException
13+
import java.net.HttpURLConnection
1314
import javax.inject.Inject
1415
import kotlin.system.exitProcess
1516

@@ -38,17 +39,8 @@ class App {
3839

3940

4041
val inputProjectCategories = inputDataRepo.getInputProjectCategories()
41-
val totalInputProjectCount = inputProjectCategories.sumBy { it.inputProjects.size }
4242
val projectMap = getProjectsMap(inputProjectCategories)
4343

44-
// This is to make sure that all project details are collected
45-
require(projectMap.size == totalInputProjectCount) {
46-
"""
47-
Expected $totalInputProjectCount but found only ${projectMap.size}.
48-
Failed to get some project details.
49-
""".trimIndent()
50-
}
51-
5244
// Now let's go build the README.md
5345
val readMeModel = readMeRepo.getReadMeModel()
5446
val updatedReadMe = ReadMeGenerator.generateReadMe(readMeModel, inputProjectCategories, projectMap)
@@ -63,7 +55,7 @@ class App {
6355
*/
6456
private suspend fun getProjectsMap(inputProjectCategories: List<InputProjectCategory>): Map<String, Project> {
6557
val projectsMap = mutableMapOf<String, Project>()
66-
58+
var shouldUpdateInputData = false
6759
for (projectCategory in inputProjectCategories) {
6860
for (inputProject in projectCategory.inputProjects) {
6961

@@ -92,12 +84,23 @@ class App {
9284
projectsMap[inputProject.githubUrl] = project
9385
println("Finished : ${inputProject.githubUrl} -> $project")
9486
} catch (e: HttpException) {
95-
println("Failed: ${inputProject.githubUrl}")
96-
throw e
87+
println("Failed: ${e.code()} ${inputProject.githubUrl}")
88+
if (e.code() == HttpURLConnection.HTTP_NOT_FOUND) {
89+
println("Removing $inputProject from input_data.json")
90+
shouldUpdateInputData = true
91+
// repo doesn't exist. so let's remove it from the `input_data.json` file
92+
projectCategory.inputProjects = projectCategory.inputProjects.toMutableList().apply {
93+
remove(inputProject)
94+
}
95+
}
9796
}
9897
}
9998
}
10099

100+
if (shouldUpdateInputData) {
101+
inputDataRepo.updateInputProjectCategories(inputProjectCategories)
102+
}
103+
101104
return projectsMap
102105
}
103106
}

Diff for: src/main/kotlin/com/github/aaka/data/repo/InputDataRepo.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ class InputDataRepo @Inject constructor(
1010
val moshi: Moshi
1111
) {
1212

13+
private val inputDataFile = File("input_data.json")
14+
private val inputDataAdapter = moshi.adapter<List<InputProjectCategory>>(
15+
Types.newParameterizedType(List::class.java, InputProjectCategory::class.java)
16+
).indent(" ")
17+
1318
/**
1419
* Get input projects
1520
*/
1621
fun getInputProjectCategories(): List<InputProjectCategory> {
1722
// Parsing data
18-
val dataJson = File("input_data.json").readText()
19-
val dataItemListType = Types.newParameterizedType(List::class.java, InputProjectCategory::class.java)
20-
val inputDataAdapter = moshi.adapter<List<InputProjectCategory>>(dataItemListType)
23+
24+
val dataJson = inputDataFile.readText()
2125
return inputDataAdapter.fromJson(dataJson)!!
2226
/*.map {
2327
it.copy(
@@ -29,4 +33,9 @@ class InputDataRepo @Inject constructor(
2933
)
3034
}*/
3135
}
36+
37+
fun updateInputProjectCategories(inputData : List<InputProjectCategory>){
38+
val dataJson = inputDataAdapter.toJson(inputData)
39+
inputDataFile.writeText(dataJson)
40+
}
3241
}

0 commit comments

Comments
 (0)