Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI Arena Human Preference 55K

Using Kotlin and Unirest implement a function fun getGithubIssue(owner:String,…

  1. User

    Using Kotlin and Unirest implement a function fun getGithubIssue(owner:String, repo:String, number:Int):GithubIssue. It only needs to return the fields number, title, body

  2. Assistant

    Sure! Here's an example implementation of the getGithubIssue function using Kotlin and Unirest:

    import com.mashape.unirest.http.Unirest
    import com.mashape.unirest.http.exceptions.UnirestException
    
    data class GithubIssue(val number: Int, val title: String, val body: String)
    
    fun getGithubIssue(owner: String, repo: String, number: Int): GithubIssue {
        try {
            val response = Unirest.get("https://api.github.com/repos/$owner/$repo/issues/$number")
                .header("Accept", "application/vnd.github.v3+json")
                .asJson()
    
            val issueJson = response.body.`object`
    
            val issueNumber = issueJson.getInt("number")
            val issueTitle = issueJson.getString("title")
            val issueBody = issueJson.getString("body")
    
            return GithubIssue(issueNumber, issueTitle, issueBody)
        } catch (e: UnirestException) {
            throw RuntimeException("Failed to fetch GitHub issue", e)
        }
    }
    
    fun main() {
        val owner = "your-github-owner"
        val repo = "your-github-repo"
        val issueNumber = 123
    
        val issue = getGithubIssue(owner, repo, issueNumber)
    
        println("Issue Number: ${issue.number}")
        println("Issue Title: ${issue.title}")
        println("Issue Body: ${issue.body}")
    }
    

    Make sure you have the Unirest library added to your project dependencies. This implementation will fetch the issue details from the GitHub API and return a GithubIssue data class with the number, title, and body fields. You can then use the main function to test the getGithubIssue function by providing your own GitHub owner, repo, and issue number.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

Identical first prompt