https://kotlinlang.org logo
Title
b

Ben Keil

04/10/2023, 1:56 AM
Do you have some thoughts, ideas about the API for workflow permissions? current implemented solution: some repetition
workflow(
    name = "test",
    permissions = listOf(
        Permission.actions.read,
        Permission.checks.read,
        Permission.contents.write,
    )
    on = listOf(),
) {
    job(id = "job", runsOn = UbuntuLatest) { run(command = "ls") }
}
other ideas: everybody understands a map, a lot of repetition
permissions = mapOf(
    Permission.Actions to Mode.WRITE,
    Permission.Checks to Mode.WRITE,
    Permission.Contents to Mode.WRITE,
),
no repetition, maybe unusual
permissions = {
    actions(write)
    checks(write)
    checks(none)
    actions(read)
},
current style of API, but no autocompletion in IDE.
permissions = listOf(
    Actions(write),
    Checks(read),
    Contents(none),
),
p

Piotr Krzemiński

04/10/2023, 6:59 AM
I would lean towards the second one because it's simple - it uses a well-known
mapOf
(also mirrors how YAML looks), provides proper discoverability for available permission and mode values. If one wants, it's possible to reduce repetition by importing individual enum values
@Ben Keil what would you recommend or be eager to use as lib user?
b

Ben Keil

04/10/2023, 7:20 AM
I think the map is the easiest thing, because it corresponds the most with the yaml specification
p

Piotr Krzemiński

04/12/2023, 12:47 PM
@Vampire any opinion worth sharing here?
it’s a small piece of API but as Ben is ramping up, he’s (correctly) challenging certain design decisions for already existing APIs. We had some interesting discussions about it
v

Vampire

04/12/2023, 12:52 PM
Actually, the only repetition I see in the original code is
Permission.
which could be mitigated by imports. Whether it looks like Yaml or not I don't think is too important. Yes, it might make it easier to onboard new users coming from Yaml. But, you know, noone likes Yaml, so don't create something that looks like Yaml or noone will like it. 😄 But besides that, if I have to choose from the 4 options, I'd probably also pick the map one.
p

Piotr Krzemiński

04/12/2023, 12:55 PM
yeah, good argument with “don’t create something that looks like YAML” - I wasn’t thinking this way until we had the discussion with Ben
v

Vampire

04/12/2023, 12:58 PM
It's no problem if it looks like Yaml. Just don't pick any choice in any decision because it looks like Yaml. Pick it because it makes the most sense independent from output format. And if it looks similar, win-win. 🙂
b

Ben Keil

04/17/2023, 10:57 AM
so it will be the map