A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/79630127/publish-android-app-dependencies-to-notion below:

kotlin - Publish Android App Dependencies to Notion

I am trying to create a gradle task for an Android App to publish all project dependencies on a Notion Page using Notion API. The issue I have is when I am trying to launch this task I get a HTTP 400 code. If I only use test to create block list it works. Any idea what the problem is ?

My task looks like this :

abstract class PublishDependenciesToNotion : DefaultTask() {

    init {
        group = "reporting"
        description = "Les dépendances dans une Page Notion"
    }

    @TaskAction
    fun run() = runBlocking {
        val notionToken = System.getenv("NOTION_TOKEN") ?: error("Missing NOTION_TOKEN env var")
        val rawPageId = System.getenv("NOTION_PAGE_ID") ?: error("Missing NOTION_PAGE_ID")
        val dependenciesList = mutableListOf<String>()

        val runtimeClasspath = project.configurations.getByName("debugRuntimeClasspath")

        runtimeClasspath.incoming.resolutionResult.allDependencies.forEach { dependency ->
            when (dependency) {
                is ResolvedDependencyResult -> {
                    val selected = dependency.selected
                    "- ${selected.moduleVersion}"
                }
                else -> null
            }?.let {
                dependenciesList += it
            }
        }

        val test = mutableListOf("one","two","three")
        val blocks = mutableListOf<Block>()

        // Lignes du fichier en paragraphes
        dependenciesList.forEach {
            blocks += Block(
                type = "paragraph",
                paragraph = Paragraph(
                    rich_text = listOf(
                        RichText(text = Text(it)
                        )
                    )
                )
            )
        }

        val request = CreatePageInDatabaseRequest(
            parent = ParentDatabase(database_id = rawPageId),
            properties = mapOf(
                "Name" to TitleProperty(
                    title = listOf(
                        RichText(text = Text(content = "📦 Dépendances Gradle"))
                    )
                )
            ),
            children = blocks.toList()
        )

        val client = HttpClient(CIO) {
            install(ContentNegotiation) {
                json(Json {
                    prettyPrint = true
                    ignoreUnknownKeys = true
                })
            }
        }

        val response: HttpResponse = client.post("https://api.notion.com/v1/pages") {
            contentType(ContentType.Application.Json)
            header("Authorization", "Bearer $notionToken")
            header("Notion-Version", "2022-06-28")
            setBody(request)
        }

        println("✅ Page Notion créée ! Status: ${response.status}, Message : ${response}")
    }
}


// --- Data classes pour Notion (version base de données) ---
@Serializable data class CreatePageInDatabaseRequest(
    val parent: ParentDatabase,
    val properties: Map<String, TitleProperty>,
    val children: List<Block>
)

@Serializable data class ParentDatabase(val database_id: String)
@Serializable data class TitleProperty(val title: List<RichText>)
@Serializable data class Block(
    val `object`: String = "block",
    val type: String,
    val paragraph: Paragraph? = null
)
@Serializable data class Paragraph(val rich_text: List<RichText>)
@Serializable data class RichText(val type: String = "text", val text: Text)
@Serializable data class Text(val content: String)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4