You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: set_attributes_service_patch.rb
    path of file: ./repos/openproject/modules/backlogs/lib/open_project/backlogs/patches
    
    the code of the file until where you have to start completion: #-- copyright
# OpenProject is an open source p
    
    def closest_story_or_impediment(parent_id)
      return work_package if work_package.is_story? || work_package.is_impediment?

      closest = nil
      ancestor_chain(parent_id).each do |i|
        # break if we found an element in our chain that is not relevant in backlogs
        break unless i.in_backlogs_type?

        if i.is_story? || i.is_impediment?
          closest = i
          break
        end
      end